The Magic of ClickOnce

by Wei-Meng Lee
Use ClickOnce to Deploy Windows Applications

Over the past few years, businesses have begun to favor deploying web applications instead of Windows applications. One of the major attractions of the web application is its ubiquitous access--anyone with a web browser can access the application, and there are no setup issues to worry about. However, network latencies and server delays are just some of the problems that are preventing developers from reaping the full benefits of the Web. Common frustrations over web applications include slow response time from web sites and limited functionality (due to the stateless nature of the HTTP protocol).

A smart client is basically a conventional Windows application that web services use to communicate with the server for back-end processing.

In this article, I will show you the support of smart clients in Visual Studio 2005 and how it makes deploying them easy and painless. Note that I won't be going into the security aspects of smart clients in this article, but the aim of this article is to give you an idea of the capability of ClickOnce, a new feature of Visual Studio 2005.

The Uses of Smart Clients

Let me share the experience of one of my customers. My customer manages a large group of agents, and each agent uses a web application provided by my customer. As the agent base grows, the response of the web server becomes a bottleneck. Moreover, the agents complain that the incessant postbacks that web applications usually perform are affecting the responsiveness of the application. Upon closer inspection, the problem lies in the complex logic embedded in the web application, and each web page contains tons of JavaScript code. All of these things add to the burden of the web server and make the application unresponsive.

Ultimately, a better solution to address the limitations of web applications is to deploy smart clients. Users would just need to download the application onto their machines once and then the application will run locally. When the application needs to access data from the server (or retrieve data from the server), web services are used.

Deploying Smart Clients

Visual Studio 2005 makes the deployment of smart clients extremely easy and painless, all through a new feature known as ClickOnce. To illustrate how ClickOnce works, I will create a new Windows application using Visual Studio 2005 and name it SmartClient. Populate the Windows form with the Calendar control, as shown in Figure 1.

Figure 1
Figure 1. Populating the Windows form with the Calendar control

Next, build the SmartClient Windows application by going to Build -> Build SmartClient. You can now publish (deploy) the application using IIS. Go to Build -> Publish SmartClient (see Figure 2) to start the Publish Wizard.

Figure 2
Figure 2. Publishing the SmartClient Windows application

You have a few options for where to publish the application--disk, shared folder, FTP server, or web server. For this article, I will show how to publish the application through the IIS web server.

Specify the location to publish the application (see Figure 3). Click Next >.

Figure 3
Figure 3. Specifying the path to publish the folder

You can let the user install the application locally on the client, or download the application every time it is needed (see Figure 4). Click Next >.

Figure 4
Figure 4. Choosing the mode the application should be run in

You would also need to sign your application. You can get the wizard to create a strong name key for your application, or create a new encrypted key. You can also use a key provider (see Figure 5). Click Next >.

Figure 5
Figure 5. Signing your application

That's it! You are now ready to publish the application through your web server (see Figure 6). Click Finish to launch the web page to install the application.

Figure 6
Figure 6. The wizard is ready to publish the application

You should see the web page shown in Figure 7. Your users can now use the URL shown to install the application on their machines.

Figure 7
Figure 7. Installing the application through the web server

To install the application, click on Install SmartClient.

Note: There is a bug in Visual Studio Beta 1 that prevents you from installing the application through the web server. To bypass this bug, use the registry editor (regedit.exe) and set the RegisteredOrganization key located in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion with a value. For my case, I have set it to my company name--Learning Solutions.

You will be prompted with a security warning (see Figure 8). Click Install to install the application onto your machine.

Figure 8
Figure 8. Installing the application

The application can now be found in the Programs sub-menu of the Start menu (see Figure 9).

Figure 9
Figure 9. Locating the installed application

Updating the Application

The power of ClickOnce lies in its ability to update applications that have already been deployed. Imagine that 200 of your customers have downloaded your application and one week later you add some new features or fix a fatal bug. In this case, it would be a logistic nightmare to inform and update the 200 customers. ClickOnce automatically ensures that your users use the latest version of your application.

Let's modify the original SmartClient application by adding a new TimePicker control to it (see Figure 10).

Figure 10
Figure 10. Adding a new TimePicker control to the Windows form

To ensure that your users use the updated application, you need to build and publish the application again, following the steps outlined earlier. That's all you need to do.

The next time your user launches the application from the Start menu, the application will automatically check the source to see if there is a newer version available. If there is one, the Update Available window will be displayed (see Figure 11). Click OK to install and use the newer version of the application.

Figure 11
Figure 11. Downloading a newer version of the application

What happens if, after installing the newer version, the user decides that he wants to use the older version? No worries; he would just go to Control Panel and click Add or Remove Programs and select the application and click Change/Remove. The user has the option to either restore the application to its previous state, or remove the application (see Figure 12).

Figure 12
Figure 12. Restore the application to its previous state, or simply remove it


In this article, I have briefly walked you through the process of deploying a smart client application using the ClickOnce feature in Visual Studio 2005. Smart client application is the new paradigm in deploying and developing your application. If you need to deploy a highly responsive networked application, the smart client model may just be the right one for you. Note that I have not discussed the security aspect of using ClickOnce; I will address this issue in a future article.

Wei-Meng Lee (Microsoft MVP) is a technologist and founder of Developer Learning Solutions, a technology company specializing in hands-on training on the latest Microsoft technologies.

Return to the

Copyright © 2017 O'Reilly Media, Inc.