http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnreal/html/realworld03232004.asp
<!--NONSCROLLING BANNER END-->Mauro Sant'Anna
Microsoft Regional Director
December 2004
Summary: Examines the ClickOnce technology, compares it to other deployment technologies, and shows how you can use it in your applications. (11 printed pages)
ClickOnce is a new Windows Forms deployment technology that will ship with Visual Studio 2005. It enables easy application installation and upgrading of Web applications with smart clients. The deployment of Windows Forms applications through HTTP has been available since the first version of the .NET Framework and has been evolving ever since. This article discusses the advantages of Windows Forms applications and the evolution of this technology leading up to ClickOnce. I will also show a simple example using the public Beta 1 version of Visual Studio 2005.
Since the World Wide Web appeared, most users and developers alike are more interested in Web applications than they are in "regular" Windows applications. Besides the "coolness factor," a Web application has some interesting and special characteristics:
The focus of this article is on the second bullet above: deployment. The HTTP protocol used by Web applications has several advantages over traditional Windows application deployment.
On the other hand, as much as I love the Web, it's hard to say that the user experience on the Web is stellar. When compared with Windows applications, the Web has several disadvantages:
What if we could marry the easy distribution of Web applications with the rich client experience of Windows applications? Well, we can. The .NET Framework since its first version allows the distribution of Windows Forms applications through HTTP and without the usual problems.
This kind of application is especially interesting in intranet/extranet scenarios, where ubiquitous access is not required and we can suppose the end user's computer will have both Internet Explorer and the .NET Framework installed.
Versions 1.0 and 1.1 of the .NET Framework came "out of the box" with the capability to deploy Windows Forms applications through HTTP. You basically use an "HREF" tag to point to a managed .EXE. Internet Explorer and the .NET Framework runtime can download and run not only the executable but also the DLLs it might require, on demand. This kind of deployment has been nicknamed "hrefing EXEs."
This is an example of such a tag:
<a href="MainProject.exe">Call MainProject</a>
This is quite easy to do and has been discussed in these recommended articles:
Because the .NET assembly (.EXE or .DLL) is the basic deployment unit, you want to break your application into a main .EXE and several DLLs. This way, if you make simple changes in a single DLL, just this DLL need to be downloaded.
As easy as it sounds, there are still some tricks to get things working correctly:
In order to address some of the issues pointed above, Microsoft created the Updater Application Block (UAB). The updater block is a library that you add to your application to manage the download of the application pieces through HTTP.
It has some advantages over the original Framework implementation:
On the other hand, there are also some disadvantages:
To get more information on the UAB, see Jamie Cool's .NET Application Updater Component. You can also check out the home of the UAB at Gotdotnet. The UAB is not "officially" supported, though there's a forum at www.gotdotnet.com. In any case, the UAB comes with full source code, and you can change it to fix some of its restrictions such as the requirement of BITS and Windows 2000.
The UAB is clearly an interim measure while Microsoft develops a definitive solution. This solution is ClickOnce. Basically, ClickOnce has all the advantages of the UAB with few of its problems, plus some added functionality. In my opinion one of the main advantage of ClickOnce is that it restores code access security.
When compared to HREF EXEs, a ClickOnce application has the following advantages:
ClickOnce is a feature of Visual Studio 2005, formerly code-named "Whidbey," and the .NET Framework 2.0. Let's explore an example using the "Community Preview Beta 1" (Framework version 2.0.40607).
Let's create a simple ClickOnce application by following these steps.
MyClickOnceApp
and click OK. Visual Basic .NET:
MsgBox("My First ClickOnce Application")
C#:
MessageBox.Show("My First ClickOnce Application");
Press F5 to run and test the application.
All Windows applications under Visual Studio 2005 have a Publish page under Project | MyClickOnceApp Properties to control deployment details:
Figure 1. Configuring publish settings
Publishing Location indicates where the application will be deployed from. It can be a Web server (HTTP) location, as shown above, but can also be a regular network path.
Install Mode and Settings controls several deployment details, such as:
Figure 2. Configuring prerequisites
Figure 3. Configuring updates
Figure 4. Configuring publish options
Publish Version adjusts the application version number; the version number can be automatically increased at each deployment.
Publish Wizard allows you to set up various publishing options. This wizard is also called from the menu Build | Publish. All ClickOnce applications must be cryptographically signed; the wizard asks for an existing key (recommended) or it can generate a new one.
Figure 5. Signing your application
After you run the wizard once, you can click Publish Now to publish updates. In our example a Web page will be shown.
Figure 6. Published application
This Web page contains a script that checks which extra Prerequisite package must be installed before installing our application. If a prerequisite is not present, it will be installed the first time the application is run.
After the user clicks the Install link, several dialog boxes may require the user's intervention, at least the first time it runs:
Visual Studio .NET 2005 will create a new Web for our application with several files and folders.
Figure 7. Deployment folders
The dotnetfx folder contains the .NET Framework redistributable, currently a 25 MB executable.
By default, Visual Studio will increase the version number each time you deploy the application; each version will get a new folder with the corresponding increasing version number.
The .application file is the target for the link shown in the HTML page publish.htm. It is an XML file that contains information such as the folder corresponding to the current version of the application and digital signatures.
Publish.htm is a Web page containing not just the link to the .application file but also some client script that does some version checking and shows messages accordingly. For instance, if your computer does not have the .NET Framework, the message shown under Install MyClickOnceApp will be different.
Setup.exe is a Win32 executable capable of installing not only your application, but as well all the necessary components such as the .NET Framework itself and MDAC 2.8 in the correct order.
Each application folder contains the application's files and also a manifest file. The manifest is an XML file with basically the following information:
After the application is downloaded, you can run it without the need to download it again. In our example, the application can be started by clicking the link to the Web page or the shortcut in the Start menu. In both cases, the existence of a new version is checked according to the settings on the Application Updates project options. A new version is downloaded if needed.
To check this update capability, do the following:
As a last note, it's important to notice that this information is based on the Beta 1 version of Visual Studio .NET; newer versions may have different features.
No changes required to the application | X | X | |
Application isolation | X | X | |
Fully supported | X | X | |
Low system impact | X | X | |
Code access security preserved | X | X | |
On demand file download | X | X | |
Manifests to declaratively list the necessary files | X | X | |
Cryptographically signed manifests | X | ||
Batch file download | X | X | |
Work offline | (*) | X | X |
Transacted installs | X | X | |
Optimum performance | X | X | |
Windows 2000 or later required | X | (**) | |
Windows shell integration | X | X | |
Good control over the update process | X | X | |
API for working offline and control the download process | X | ||
Automatic installation of optional packages | X |
(*) Requires user intervention
(**) Too early to say for a beta product
ClickOnce is a very powerful technology for application deployment. It's a natural evolution of the deployment models available previously, bringing together robustness, security, performance, and flexibility to the rich client experience of Windows Forms applications.