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.
Usage
To set up the dlls, see
Increment Build Numbers (major, minor, build, etc).
Script
<!--Auto-increment the version number-->
<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"/>
<!-- This target is called after Team build gets all the source files from TFS. -->
<Target Name="AfterGet" DependsOnTargets="VersionExes" />
<!--Replace the previous version in the exe with the new changeset number-->
<Target Name="VersionExes">
<Message Text="Version File is $(VersionFile)" Importance="normal"/>
<!--Get the most recent changeset in our project-->
<TfsVersion LocalPath="$(SolutionRoot)">
<Output TaskParameter="Changeset" PropertyName="ChangesetNum"/>
</TfsVersion>
<Message Text="Building at changeset $(ChangesetNum)" />
<SourceTfs.Checkout Path="$(VersionFile)" />
<!-- Update the version number in the exe file -->
<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>
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.