Nov
11
2009

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:

  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
  1. <!-- Deploy Click Once-->
  2. <Target Name="DeployClickOnce">
  3.   <Message Text="####### Deploy ClickOnce $(Configuration)|$(Platform)  ---------#" />
  4.   <Exec Command="xcopy /E /Y $(ClickOnceSrc)\*.* $(ClickOnceDestination)" />
  5.   <Copy SourceFiles="$(ClickOnceDestination)\Publish.htm.ori" DestinationFiles="$(ClickOnceDestination)\Publish.htm" />
  6.   <FileUpdate
  7.     Files="$(ClickOnceDestination)\Publish.htm"
  8.     Regex="2.0.0.x"
  9.     ReplacementText="$(FullVersion)" />
  10. </Target>

and the FullVersion is defined as this, using TeamCity BUILD_VCS_NUMBER, which is Latest VCS revision:

  1. <Major>2</Major>
  2. <Minor>0</Minor>
  3. <Build>0</Build>
  4. <Revision>$(BUILD_VCS_NUMBER_app_Trunk)</Revision>
  5. <FullVersion>$(Major).$(Minor).$(Build).$(Revision)</FullVersion>  </PropertyGroup>

And now the Publish webpage display the version correctly!

4094558371_70b24140cc_o[1]

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About Laurent

Laurent Kempé

Laurent Kempé is the editor, founder, and primary contributor of Tech Head Brothers, a French portal about Microsoft .NET technologies.

He is currently employed by Innoveo Solutions since 10/2007 as a Senior Solution Architect and certified Scrum Master.

Founder, owner and Managing Partner of Jobping, which provides a unique and efficient platform for connecting Microsoft skilled job seekers with employers using Microsoft technologies.

Laurent is awarded by Microsoft since Avril 2002: Most Valuable Professional (MVP).

MVP
Certified ScrumMaster
JetBrains Academy Member

My status

Twitter

Flickr

www.flickr.com
This is a Flickr badge showing public photos and videos from Laurent Kempé. Make your own badge here.

Month List

Page List