Creating a ClickOnce application

show more Creating a ClickOnce application provides you with in-depth training on Developer. Taught by Walt Ritscher as part of the Visual Studio 2010 Essential Training show less
please wait ...

Creating a ClickOnce application

ClickOnce is an alternative to the standard Windows installer. The name refers to the fact that the user is prompted once to install the app. The more compelling reason to use ClickOnce, however, is for its automatic update feature. Here is the idea: When you deploy your application you embed a URL in the application. Then you deploy a special manifest file to that URL. The manifest contains information about the application itself and a list of application files and prerequisites. Whenever your application is started, the ClickOnce engine checks that URL to see if the manifest has changed.

If so, the application is updated based on the contents of the manifest file. I've used ClickOnce successfully on several projects, and I have to say that it's easy to use and works as advertised. I'm opening a solution called ClickOnceDeploy, which contains our PixelSmithDesktop WPF application. To do a ClickOnce deployment, you just need to open this Properties node and go to the Publish section. I would like to talk about security keys first. You have to sign your manifest. It's easy to sign by going to the Signing tab and using this Sign the ClickOnce manifests.

I have already created a temporary test certificate key. If you want to create your own, just click on this Create Test Certificate key and it will replace the existing one. Next, I'll go to Publish, and we'll talk about these two locations. There is the Publishing Folder Location and the Installation Folder location. The Publishing Folder Location is where Visual Studio copies the files during a publish operation. The Installation Folder URL is where the user goes to install the application. These may be the same location, and they might be different.

Let me tell you a reason why they might be different. Let's say we're deploying off of a web server. I don't have permissions to upload files to that server. I will have to give them to my IT administrator. So I'll publish to a local location. Then when I'm done, I'll zip those up and send them to my administrator and say, "These need to be installed on our web server." I do need to embed the correct HTTP location here though, because that's where your application is going to go look for the manifest. For today, we're going to use the same location to make our lives easier.

I'm going to go out to our Desktop, and I'm going to create a new folder on the desktop called Deploy. Then I'm going to open that Deploy folder, and then I'll click up here and copy the location. Then I return back to Visual Studio, and I'm going to paste that location in this Publishing Location. Now, I'm going to have to change this to localhost, and then I'll take and copy this and paste it down here in the Installation Folder location. Next, I'm ready to publish. I will walk you through the wizard, so you can see how that works.

I'll click on the Publish Wizard. This just asks where the publishing folder is. I'll go ahead and click the Next button. Here, I can specify where the user will install the application: from a web site, or from a local file, or from a CD-ROM. Naturally, we're choosing this local location. Next, I choose whether I want to have the application run offline or not. In other words, if the web site is not available, will this application is still run? I'll click Next and then Finish. It opens this folder, which is my Desktop\Deploy location, and let's look at what we have here. This is the file that the user will run to install the application.

This is the manifest file. It contains XML data, pointing out what the current version of the application is. This folder contains all the physical files that need to be installed on the user's machine. So if I open up the Application Files folder, here is our first version of our application, and inside there are the files that need to be copied to the user's install folder. I'm going to go back here and double- click on setup.exe, step through the prompts. The reason I get this is because I'm not using a real security certificate; I'm using a test certificate. Click on Install, and now the application is running.

We'll check out and make sure it's working. Looks good, and then I'll close the app. Now the next day your user comes into work, they go down here, and they choose to run PixelSmithDesktop. I don't know if you saw that, but very briefly there was a Checking for Updates dialog that popped up. It didn't find any new updates, so it just went ahead and ran the application. I'm going to make some changes to the application over inside Visual Studio. So I'm going to go to my UI, and I'm going to change some text on this ToolBox.

I'm going to come over to the Text property and put an extra x in there and then compile my application. So now I have a new version. Let's publish that new version. We'll go back to the Publish location. Rather than click on the Publish Wizard, I can just click on the Publish Now. Let's go look in this folder. You see how there is two versions here now? And this manifest file is now pointing to the second version. So, the user now goes to their shortcut on their desktop, and they see this dialog, "A new version of PixelSmithDesktop is available.

Do you want to download it now?" Of course we do. We'll click on OK, and now there is our new improved version of the application. There is more to explore in ClickOnce. For example, it exposes a programming model so that you can write code to check for updates. I'm a firm believer in the power of this tool, and I love how ClickOnce streamlines the update processes for my application.

Creating a ClickOnce application
Video duration: 5m 13s 8h 9m Intermediate


Creating a ClickOnce application provides you with in-depth training on Developer. Taught by Walt Ritscher as part of the Visual Studio 2010 Essential Training

please wait ...