A few weeks ago I was doing some work with a client in Sydney helping migrate their existing code base across to Team Foundation Server. One of the developers who also happens to play the build master/release manager role asked me if there was a better way of deploying their software.

Their current approach was copying the files onto a network share and adjusting the security policy of the user workstations to allow that code to execute with full trust. One of the problems that they were running into was that in order to update the program they had to rename all the files before deploying because they were locked by users who were currently using the software.

This was a fairly common approach back in the .NET 1.0/1.1 days, and if you wanted to get around it you had to build some kind of boot strapper that would set up an application domain and shadow copy the files, similar to the way that ASP.NET does to avoid file locking.

Fortunately, in a .NET 2.0+ world Microsoft has made our lives a little bit easier with the introduction of ClickOnce, although not everyone knows of its existence. I told the client about ClickOnce and they went off and did some experimentation.

The following week I visited the client again and I got the obvious question – how do we get ClickOnce working with Team Build?

The good news is that it isn’t that hard as Team Build has built-in support for working with ClickOnce enabled projects. The steps that you need to follow are:

  1. Enable ClickOnce in your application (you can do this via the properties window, or by doing step two below).
  2. Do one ClickOnce deployment manually to make sure all the appropriate configuration entries are written to the project file.
  3. Edit the TFSBuild.proj file and copy the “SolutionToBuild” line, and put it below, and rename it to “SolutionToPublish”. The screen show below provides an example. 

Sample from the configuration file.

Team Build will then build the code and place a versioned ClickOnce directory in the drop folder that you can then copy over to your deployment location. If you are feeling adventurous you could even use TFS Deployer to automate this step.