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\(&quot;[^&quot;]*&quot;\)" 
              ReplacementText ="AssemblyDescription(&quot;$(BuildNumber)&quot;)" />
</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:

posted on Thursday, July 06, 2006 4:07 PM by jatwood

Comments

# Adding build numbers to your binaries using Team Build.

Thursday, July 06, 2006 11:58 PM by notgartner.com: Mitch Denny's Blog

# VSTS Links - 07/07/2006

Rob Caron on FTPOnline - Special Report: Visual Studio Team System, TheServerSide.NET - Team System and...
Friday, July 07, 2006 6:59 AM by Team System News

# Volete sapere con quale build sono stati creati i vostri eseguibili

Saturday, July 08, 2006 5:06 AM by Lorenzo Barbieri @ UGIblogs!

# Adding build numbers to your binaries using Team Build.

Correlating binaries to a particular build in Team Foundation Sever is actualy quite useful for developers,
Tuesday, July 11, 2006 6:20 PM by Community Blogs

# re: Adding the Build Number to your Team Build binaries

pretty neat but what if I'm building incrementally i.e. this process will update all assemblyinfo files and msbuild will think that that all assemblies need rebuilding as one of its source files has changed
Sunday, August 13, 2006 12:00 PM by Simon Burgess

# Custom Build Numbers in Team Build

The Team Build service in Team Foundation Server includes the current date in the build number by default.
Friday, October 20, 2006 3:20 AM by ASP.NET Chinese Blogs