Automating Publish of ClickOnce with TeamCity
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:
Copy Publish.html.ori to Publish.htm
Use FileUpdate of MSBuild Community Tasks to search the 2.0.0.x string and replace it with the version
<Target Name=“DeployClickOnce“>
<Message Text=“####### Deploy ClickOnce $(Configuration)|$(Platform) ———#“ />
<Exec Command=“xcopy /E /Y $(ClickOnceSrc)*.* $(ClickOnceDestination)“ />
<Copy SourceFiles=“$(ClickOnceDestination)\Publish.htm.ori“ DestinationFiles=“$(ClickOnceDestination)\Publish.htm“ />
<FileUpdate
Files=“$(ClickOnceDestination)\Publish.htm“
Regex=“2.0.0.x“
ReplacementText=“$(FullVersion)“ />
</Target>
and the FullVersion is defined as this, using TeamCity BUILD_VCS_NUMBER, which is Latest VCS revision:
- <Major>2</Major>
- <Minor>0</Minor>
- <Build>0</Build>
- <Revision>$(BUILD_VCS_NUMBER_app_Trunk)</Revision>
- <FullVersion>$(Major).$(Minor).$(Build).$(Revision)</FullVersion> </PropertyGroup>
And now the Publish webpage display the version correctly!
[](http://weblogs.asp.net/blogs/lkempe/4094558371_70b24140cc_o1_670E614B.png)