Team Foundation Build Recipes

Update the version number of a C++ project

Modified: 2008/05/10 08:47 by MarcT - Uncategorized
Edit

Description

This recipe gets the latest changeset from TFS and appends it to the version number in an RC file. It uses both the Sdc tasks and the MSBuild Community Tasks, both of which are linked on the main page.

Edit

Usage

To set up the dlls, see this page.

Edit

Script


  <PropertyGroup>
    <VersionFile>$(SolutionRoot)\Path\To\Your.rc</VersionFile>
  </PropertyGroup>
  <UsingTask AssemblyFile="Microsoft.Sdc.Tasks.dll" TaskName="Microsoft.Sdc.Tasks.SourceTfs.Checkin"/>
  <UsingTask AssemblyFile="Microsoft.Sdc.Tasks.dll" TaskName="Microsoft.Sdc.Tasks.SourceTfs.Checkout"/>
  <UsingTask AssemblyFile="Microsoft.Sdc.Tasks.dll" TaskName="Microsoft.Sdc.Tasks.File.Replace"/>
  <UsingTask AssemblyFile="MSBuild.Community.Tasks.dll" TaskName="MSBuild.Community.Tasks.Tfs.TfsVersion"/>

  
  <Target Name="AfterGet" DependsOnTargets="VersionExes" />

  
  <Target Name="VersionExes">

    <Message Text="Version File is $(VersionFile)" Importance="normal"/>
    
    <TfsVersion LocalPath="$(SolutionRoot)">
      <Output TaskParameter="Changeset" PropertyName="ChangesetNum"/>
    </TfsVersion>
    <Message Text="Building at changeset $(ChangesetNum)" />
    
    <SourceTfs.Checkout Path="$(VersionFile)" />
    
    <File.Replace Path="$(VersionFile)"
                  NewValue="FILEVERSION $1,$2,$3,$(ChangesetNum)"
                  regularExpression="FILEVERSION (\d+),(\d+),(\d+),(\d+)"
                  TextEncoding="windows-1250" />
    <File.Replace Path="$(VersionFile)"
                  NewValue='"FileVersion", "$1, $2, $3, $(ChangesetNum)"'
                  regularExpression='"FileVersion", "(\d+), (\d+), (\d+), (\d+)"'
                  TextEncoding="windows-1250" />
    <SourceTfs.Checkin Path="$(VersionFile)"
                       Comments="Automated Build: Updating exe version to $(ChangesetNum)"
                       WorkingDirectory="$(SolutionRoot)" />
  </Target>

Edit

Notes

  • The TextEncoding parameter in the File.Replace task is broken as of 5-9-2008. A patch has been submitted, and it will be fixed in the next release of the Sdc Tasks after that date. Without the patch, File.Replace keeps changing your .rc file to UTF-8, which VS does not support.

© 2008 William Bartholomew blog.bartholomew.id.au

Powered by screwturn wiki