Deploying Windows Forms Applications With ClickOnce
Deploying Windows Forms Applications With ClickOnce
● A Web application can be accessed from anywhere in the world where an Internet connection is
available; the client doesn't even need to be running Windows. A "pure Web" application is a very
good technology when your application needs ubiquitous access.
● A Web application is easy to deploy and update: just copy the application files into a directory on a
Web Server and all your clients can start using the new application instantly. No DLL hell, no registry
entries to tangle with, no COM classes to register; it just works!
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:
● Its user interface is quite poor. Things that we take for granted in a Windows application, such as
drag and drop and right-clicking the mouse, are very hard or even impossible to do in a Web
application.
● Even when we do manage to do rich interface tricks, it usually requires an insane amount of client
script, a kind of code that is particularly hard to write and debug.
● A Web application uses a lot of server resources, bandwidth, and user patience because most
things have to be done at the server with a round trip and some waiting involved.
● Printing is limited to "print screen technology," with little control over things like page breaks due to
different fonts, margins, and paper size.
● Some of the problems above can be mitigated through the use of plug-ins or ActiveX controls, but
those in turn tend to have the same deployment problems that the old non-Web applications used
to have.
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.
ClickOnce
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:
● Updates are transacted (that is, are either done fully or not at all).
● The application not only can work offline but it has a degree of control over it; there are APIs so that
the application can find out if it's online or offline; it can also control its own update process;
● It has good integration with Visual Studio .NET, including the ability to generate the appropriate
extra files and tools that help to figure out which security privileges your application need in order to
run.
● It comes with a Win32 "bootstraper" executable that can download necessary components, even
the .NET Framework itself.
● Application files can be downloaded on demand or in batches;
● It can have Start menu shortcuts;
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).
A ClickOnce Application
Let's create a simple ClickOnce application by following these steps.
C#:
MessageBox.Show("My First ClickOnce Application");
● Updates: Controls when the application should check for updates and how those updates are
brought to the client.
Figure 3. Configuring updates
● Options: Adjusts details such as application language, Start menu shortcut resource name, HTML
page used for Web deployment, and the deployment policy ticket.
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.
Deployment Details
Visual Studio .NET 2005 will create a new Web for our application with several files and folders.
● Precise identity of all the application's files. This identity comprises the file name, version number,
culture, and processor architecture ("msil" in our case).
● All the permissions the application requires.
● Digital signatures.
1. Make a visible change to the application, such as changing the location of the button on the form.
2. Build and deploy it again.
3. Run the application and check the download process.
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.