Automate ClickOnce with Nant


Problem: You need to deploy a clickonce enabled application using NAnt script.


Solution: Use the MSBuild, version, exec and copy tasks from the NAnt, and NAntContrib Projects.


            When using the clickonce publish wizard, the wizard does some neat things for you. First it increments the version, builds the project then it generates some manifests, signs the manifests, generates a default html page, creates a setup.exe and finally copies all the needed files to your deployment location. This great up until you want to automate this build process and you find out not all of these tasks are being handled in msbuild.


Incrementing Version with NAntContrib task version. I also like to automatically update and commit this version number (the file build.number) so that everyone on the team is on the same page.



Use the MSBuild task from NAntCotrib on the project that is setup for clickonce deployment and use Publish as the target. This will build the project, generate the manifest, sign the manifest, and create the setup.exe. This will not generate a default.htm page; you must create this by hand. I just create a page using the generated page as a template and the application manifest as a datasource to get current build information.


 <!--Get the latest buld number from repositiory-->
<target name="versioning">
<exec program="svn.exe" basedir="tools\svn" 
commandline="up build.number 
--username username 
--password password 
<!--Increment buld number-->
<version buildtype="NoIncrement" revisiontype="Increment" />
<!--Commit buld number to repositiory-->
<exec program="svn.exe" basedir="tools\svn" 
commandline="commit build.number 
-m AutomatedCommit 
--username username 
--password password 


Finally I just copy the files to the production server.


<!--Copy production files to the server-->
<target name ="publish.clickonce"> 
  <copy todir="${Production.dir}">
    <fileset basedir="${ClickOnce.dir}">
      <include name="**/*" />

Complete Source: This contains everything I used for the example the click once hello world project, my project tree, build tools, and build file. (3.93 MB)


How to create a SelfCert .pfx file to sign manifest.

ClickOnce on Multiple Environments

Versioning Using NAnt