Quick Apps With ClickOnce

Smart client easily distributes Windows applications over the Net

InformationWeek Staff, Contributor

September 3, 2010

3 Min Read
InformationWeek logo in a gray background | InformationWeek

ClickOnce is a Microsoft technology that enables a Windows Form or Windows Presentation Foundation application to be deployed via a Web page. The main advantage of ClickOnce is that it lets users decide whether to install an application upgrade.

With ClickOnce, a "smart client" application is installed in a sandbox on the client machine with fewer rights than it would otherwise get. For example, the client has no access to local files, and it's installed in a user's private folder, not in the Program Files.

For example, to make the Windows Calculator available via ClickOnce, go to the CiDotNet.WinCalc project properties and switch to the Publish tab. You'll need a Web server like Microsoft's Internet Information Services to host your published apps.

To launch a publication, press the Publish Now button or use the publishing wizard, then launch Internet Explorer and open the remote location. (Firefox and other browsers require ClickOnce plug-ins.) Publishing a ClickOnce application in Visual Studio is straightforward: You can either use command-line tools like mage.exe or MSBuild (as we do here). Generate the publication files in MSBuild by using the Publish target on the solution file, like this:

Msbuild CiDotNet.sln /t:Publish

There are problems with this approach: The version number isn't incremented; the publication files are created in the bin\$(Configuration)\app.publish folder, not on the destination location; and the Web site HTML file isn't generated. The version number can be set from outside by providing the ApplicationVersion property on the MSBuild command line:

Msbuild CiDotNet.sln /t:Publish /p:

ApplicationVersion=1.0.0.3.

To get the version number on the build server, Visual Studio takes it from the ApplicationRevision property inside the .csproj file. It's a good idea not to mess with it on the server.

What 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. The easiest way to get the files copied to the Web server is to define the target location: <Deployment Folder>\\ci1\WinCalc\</Deployment Folder>. Then, gather the source files and copy the publishing files after they're created.

The last problem is the lack of HTML. There's no elegant way to deal with this; however, you can create a template using the index.html Web site. Just copy the index.html file to the solution project folder and change the current version to a string stored in the ApplicationVersion variable using the FileUpdate task from the MSBuild Community Tasks.

The HTML template gives you another opportunity to customize the ClickOnce Web site and provide additional information to the user. First, we take the custom HTML "template" file, together with an application screenshot, and copy it to a destination folder. Next, we apply the FileUpdate task, search for the ApplicationVersion string, and replace it with an updated version number. Don't forget to import the FileUpdate task from MSBuild Community Tasks.

You can set the build script so that your continuous integration server uses it every time something changes in the repository, and a new application will be deployed with each update.

Marcin Kawalerowicz runs a consultancy in Silesia, Poland. Craig Berntson has been a Microsoft MVP since 1996. They are the authors of "Continuous Integration With .NET." Write to us at [email protected].

Never Miss a Beat: Get a snapshot of the issues affecting the IT industry straight to your inbox.

You May Also Like


More Insights