Published: 02 Apr 2010
By: Manning Publications

This article is taken from the book Continuous Integration in .NET. The authors discuss ClickOnce, a simple way to make a Windows application available over the net without using installation files. They show how to use ClickOnce within the Continuous Integration process.

Contents [hide]

About the book

This is a sample chapter of the book Continuous Integration in .NET. It has been published with the exclusive permission of Manning.


Written by: Marcin Kawalerowicz and Craig Berntson
Pages: 375
Publisher: Manning
ISBN: 9781935182559

Get 30% discount

DotNetSlacker readers can get 30% off the full print book or ebook at www.manning.com using the promo code dns30 at checkout.

Introduction

ClickOnce is a Microsoft technology that lets you easily deploy your Windows application, whether it's a Windows Form or Windows Presentation Foundation (WPF) application, via a web page. Applications deployed in this manner are sometimes called smart clients. This application is installed within a sandbox on the client machine and has fewer rights than a normally installed application. One limitation is that the application has no access to local files. It is not installed in the Program Files folder but in the private folder of the user that installs the application. The advantage of ClickOnce deployment is that whenever a new version of the application is available on the Web site, the user can decide whether or not to install the upgrade. It you like this approach, you can easily incorporate it into your CI process and make the new version available after every check in. Interested? Let's see how to do it.

Creating a ClickOnce deployment

We will make our Windows Calculator available with ClickOnce. In order to do this, go to the CiDotNet.WinCalc project properties and switch to Publish tab (Figure 1).

Figure 1: The Publish properties for windows application. The install is deployed to a share in the local network that is available over http.

The Publish properties for windows application. The 

install is deployed to a share in the local network that is available over http.

You will need a web server, IIS works, to host your ClickOnce published applications. Figure 1 shows a publishing target laying somewhere in the local network. In our test setup, IIS is installed on the ci1 server, sees the WinCalc folder, and is able to immediately host the WinCalc application. If you have Front Page Extensions installed on the remote IIS server you will be able to publish onto it right away.

In order to make the published version look nice you should define the deployment web page. Click on the Options... button. Fill in the Description then select Deployment from the listbox (Figure 2).

Figure 2: Defining the deployment web page for the ClickOnce deployment

Defining the deployment web page for 

the ClickOnce deployment

It's time for a test publication. Press the Publish Now button or use the publishing wizard. Then, launch Internet Explorer and open the remote location. Be advised that Firefox and other browsers do not support ClickOnce without special plugins.

Figure 3: A published ClickOnce application on a web page

A published ClickOnce application on a web page

Now, if you click Install, WinCalc will be installed on your computer. The whole process works like a charm from Visual Studio. With a command line (and eventually CI), it is not so easy, as you will see next.

ClickOnce in a CI scenario

Publishing a ClickOnce-based application in Visual Studio is very easy, as opposed to the automated deployment. But it's still tricky and, if you want to do it, you can either use a command line tools like mage.exe or you can have MSBuild to do the work for you. As we are the masters of MSBuild now, we will use this build tool.

You can generate the publication files using MSBuild by using the Publish target on the solution file, like this:

There are several problems with this approach:

  • The version number is not incremented.
  • The publication files are created in the bin\$(Configuration)\app.publish folder and not on the destination location.
  • The website html file is not generated at all.

Let's deal with these issues one at the time. The version number could be set from outside by providing the ApplicationVersion property on the MSBuild command line:

But how do we get the version number on the build server? Visual Studio takes it from the ApplicationRevision property inside the .csproj file and it will not be a good idea to mess with it on the server. But how about combining the ApplicationVersion number with the revision number?

First, make sure the MSBuild community tasks have been copied into the tools directory. Next, get the svn.exe and copy it to svn subdirectory in the tools folder. We'll use them both, as shown in Listing 1.

Listing 1: Publishing an application versioned with SVN revision number

After importing the SvnInfo MSBuild Community task we define the immutable #1 and mutable #2 version number parts. In the Publish target, we get the RevisionNumber #3 using the SvnInfo task and apply it to the ApplicationVersion property #4. Problem one, setting the version number, is now solved.

The second problem is that the files are not copied to the target location. The ClickOnce files are created in bin\$(Configuration)\app.publish folder. They need to be copied to the web server. The easiest way is to define the target location like:

The gather the source files:

After the publishing files are created they can be copied:

The last problem is the lack of the HTML website. There is no elegant way to deal with that. The best solution is to take the created index.html Web site and create a kind of template with it. Let's copy the index.html file to the solution project folder and change the current version to a string stored in the ApplicationVersion variable. We will use the FileUpdate task from the MSBuild Community Tasks. Check out Listing 2 for the file update usage.

Listing 2: Updating publication version in ClickOnce HTML self-made template file

The use of the HTML template gives you one more opportunity to customize the ClickOnce website to suit your needs. For example, you can provide additional information to the user. First, we take the custom-made HTML "template" file together with an application screenshot and copy it to the destination folder #1. Afterward we apply the FileUpdate task, search for the ApplicationVersion string, and replace it with the version number #2. Don't forget to import the FileUpdate task from MSBuild Community Tasks. Your ClickOnce Web site could look like that in Figure 4.

Figure 4: A customized ClickOnce website generated directly from the build server

A customized ClickOnce 

website generated directly from the build server

You can take this build script and set it to make your CI server use it every time something changes in the repository. You will get a brand new application deployed every time something changes in the repository.

Summary

Automating delivery and deployment and incorporating it into the CI process is a very natural thing to do. It feels quite right to take the compiled, tested, analyzed and documented code that looks like a delicious sweet candy and wrap it up with colorful wrapping.

The delivery and deployment scenarios depend on your individual needs. You can, for example, provision some Virtual PC setups just like the physical ones. You might want to add the automatically generated documentation to the package. You may also need to take into account laws, such as Sarbanes/Oxley (SOX) in the United States, which prohibit development from touching QA or production servers. In this case, you can use agents on QA and production servers to get the latest build. Finally, you might want to create some safety net functionality in your build script to redo the changes if something goes wrong.

Get 30% discount

DotNetSlacker readers can get 30% off the full print book or ebook at www.manning.com using the promo code dns30 at checkout.

<<  Previous Article Continue reading and see our next or previous articles Next Article >>

About Manning Publications

Manning Publication publishes computer books for professionals--programmers, system administrators, designers, architects, managers and others. Our focus is on computing titles at professional levels. We care about the quality of our books. We work with our authors to coax out of them the best writi...

This author has published 33 articles on DotNetSlackers. View other articles or the complete profile here.

Other articles in this category


Android for .NET Developers - Location and Maps
In Windows Phone and iOS getting the current position of the device in terms of latitude and longitu...
Android for .NET Developers - Using Web Views
In this article, I'll show a native app that contains a web-based view. The great news is that HTML ...
Android for .NET Developers - Building a Twitter Client
In this article, I'll discuss the features and capabilities required by an Android application to ta...
Ref and Out (The Inside Story)
Knowing the power of ref and out, a developer will certainly make full use of this feature of parame...
Developing a Hello World Java Application and Deploying it in Windows Azure - Part II
In this article we will see the steps involved in deploying the WAR created in the first part of thi...

You might also be interested in the following related blog posts


Using Mage to modify ClickOnce deployment settings for WPF applications read more
Productization read more
How do I deploy an application and its prerequisites? (Mary Lee) read more
StreamInsight read more
Trials & Tribulations of running windows scripts in Vista read more
Using VSTS to Quickly Test Scenarios with Add-In Applications read more
Silverlight minor update released today read more
Reporting Q2 2009 release read more
Visual WebGui Cloud-friendly technology read more
Giving WPF Some Love read more
Top
 
 
 

Discussion


Subject Author Date
placeholder simple but useful. Justin Liu 4/11/2010 8:59 AM
click once deployment Dummy Ahuja 2/1/2011 6:58 AM
placeholder Very Nice Scott Lafoy 12/15/2011 12:24 PM

Please login to rate or to leave a comment.