The other day I published different posts about the way I automated our build process at Innoveo Solutions to generate different ClickOnce setup using TeamCity:

Build multiple ClickOnce deployment packages using MSBuild and Team City

Building ClickOnce with TeamCity
ClickOnce certificate and TeamCity
Build ClickOnce deployment packages using MSBuild and Team City

Yesterday I was asked to solve one minor issue. At ClickOnce publishing time the publish.htm file was not generated so the ClickOnce version number on the web page wasn’t shown. The publish.htm file is a static file on the targeted deploy directory and IIS uses that file. The file contains a hard coded version 2.0.0.x.

So from a user perspective it was difficult to know if there were a new version. So I was asked to show the correct version.

I knew from past research a way to handle this from the following post: How To: Generate publish.htm with MSBuild

But I went to a more pragmatic solution, as I already had the MSBuild Community Tasks.

I made a copy of Publish.htm to Publish.htm.ori on each targeted deploy directory.

Then I modified my MSBuild script to do the following:

  1. Copy Publish.html.ori to Publish.htm

  2. Use FileUpdate of MSBuild Community Tasks to search the 2.0.0.x string and replace it with the version

  3. <Target Name=DeployClickOnce>

  4.   <Message Text=####### Deploy ClickOnce $(Configuration)|$(Platform)  ———# />

  5.   <Exec Command=xcopy /E /Y $(ClickOnceSrc)*.* $(ClickOnceDestination) />

  6.   <Copy SourceFiles=$(ClickOnceDestination)\Publish.htm.ori DestinationFiles=$(ClickOnceDestination)\Publish.htm />

  7.   <FileUpdate

  8.     Files=$(ClickOnceDestination)\Publish.htm

  9.     Regex=2.0.0.x

  10.     ReplacementText=$(FullVersion) />

  11. </Target>