Adding the Build Number to your Team Build binaries
If you're using Team Build, you may want to "tag" the binaries produced with the name of the build.
In order to do this, we'll customize the Team Build script (TFSBuild.proj) for the project, hooking in to the default Team Build BeforeCompile event. Check TFSBuild.proj out via the Source Control Explorer, and open it for editing. Add these lines to the bottom of the build script:
<!-- customized extensibility event BeforeCompile -->
<Target Name="AfterGet" DependsOnTargets="VersionAssemblies">
<Message Text="AfterGet is firing!"/>
</Target>
<!-- add build number to AssemblyDescription field -->
<Target Name="VersionAssemblies" DependsOnTargets ="GetAssemblyInfos">
<Attrib Files="@(AssemblyInfos)" ReadOnly="false"/>
<FileUpdate Files="@(AssemblyInfos)" Regex="AssemblyDescription\("[^"]*"\)"
ReplacementText ="AssemblyDescription("$(BuildNumber)")" />
</Target>
<!-- get a list of all AssemblyInfo files -->
<Target Name="GetAssemblyInfos">
<CreateItem Include ="..\**\AssemblyInfo.cs">
<Output ItemName ="AssemblyInfos" TaskParameter="Include"/>
</CreateItem>
<Message Text="These AssemblyInfo.cs files were found:"/>
<Message Text ="@(AssemblyInfos)"/>
</Target>
You'll also need to download the MSBuild Community tasks, and install those on your build server. Add a reference to the MSBuild Community tasks near the top of your TFSBuild.proj file, like so:
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
Check in the TFSBuild.proj file, then perform a build.. and watch the magic happen!
What we're really doing is popping the $(BuildNumber) variable into the AssemblyInfo.cs file. Specifically, we're putting it in the AssemblyDescription field:
[assembly: AssemblyTitle("WindowsFormsClient")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Vertigo Software")]
[assembly: AssemblyProduct("WindowsFormsClient")]
[assembly: AssemblyCopyright("Copyright © Vertigo Software 2006")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
After executing the build, note that the binary files will have the build number in the Comments area in the standard Windows file properties dialog: