Introduction to ClickOnce

Before learning about ClickOnce and how it works, it is beneficial to learn the problems that it solves. In traditional software installation packages, there are several issues that can be difficult for developers to get around that make the entire development process take more time (and therefore cost more money). When a user receives a Windows

Installer package either from a CD or from a web download, that user must run that installation package to install the software. This often requires administrative privileges on the computer. After the software is installed, new versions, releases, updates, and patches often require that the previous version be completely removed before the new version can be installed. In addition, the new version is often a completely new package that contains the entire application rather than just the portions that have changed. Applications like many antivirus packages have built in their own custom update technology to allow the application to update itself once installed, but it still must be installed using a Windows Installer package that might require administrative privileges.

ClickOnce is a technology introduced with version 2.0 of the .NET Framework that provides a means by which developers can quickly and easily publish their applications. In addition to simplified deployment, ClickOnce allows applications to automatically receive updates from a central location that will only be downloaded as they are needed. Finally, ClickOnce also ensures that when a new version is placed in the publication location (which can be a network share or a location on the web), only the assemblies that are required are downloaded.

As you will see throughout the remainder of this chapter, security is taken care of by storing ClickOnce applications in an isolated per-user, per-application "sandbox" that prevents the application from interfering with other installed applications. ClickOnce applications don't inherently require administrative privileges, they don't require expensive and time-consuming uninstalls to make way for new releases, and they only download what they need. All of this functionality has been embedded directly into the .NET Framework and will dramatically increase your power to deploy and update your applications.

Although ClickOnce is an incredibly powerful new technology, it is also designed for applications that are running in a somewhat isolated environment. ClickOnce installations cannot make global changes for shared libraries. There are still a few scenarios in which you would want to use a Visual Studio Setup Project (Windows Installer) to deploy your application.

Tip

One scenario that is not often mentioned in documentation of ClickOnce applications is that you can use Windows Installer (Visual Studio 2005 "Setup" project) to deploy a ClickOnce application on a CD or download. After the user installs this application, the autoupdate functionality of ClickOnce can take effect. In other words, you can deploy a ClickOnce application using Windows Installer if you have complex initial setup requirements, but you still want to be able to "push" updates via the ClickOnce update mechanisms.

Table 39.1 shows a comparison of features between Windows Installer deployment and ClickOnce deployment to help you get an idea of when to use each technology. A more detailed version of this table is also available on MSDN.

Table 39.1. Feature Comparison: ClickOnce Versus Windows Installer

Feature

ClickOnce

Windows Installer

Automatic update

(requires additional code in the app)

Automatic rollback after installation

Download updates from the web

Affects shared components/other apps

Permissions granted

Only necessary

Full trust

Permissions required

Internet/Intranet Zone

Administrator

Manifest (app and deploy) signing

Installation GUI

Y/N Prompt

Wizard

On-demand file install

Install shared files

Install assemblies in GAC

Install for multiple users

Add shortcut to Start menu

Add shortcut to Startup

Add application to Favorites

Register new file types/extensions

Application install location

ClickOnce Cache

Program Files

What it all boils down to is that using ClickOnce to deploy your applications is extremely fast and flexible, provided your application doesn't need to make changes to global resources and settings. ClickOnce is ideal for deploying Smart Clients that typically have small footprints and provide a rich, interactive user interface that operates against a web service or relational database back end.