Rob Smyth

Friday 8 June 2007

Using Subversion Revision as the AssemblyVersion

Today I spent a few hours configuration our work projects to automatically use the Subversion (SVN) revision number as the assembly version in the AssemblyInfo.cs file in each project.

The motivation was:
  • Give direct traceability from the build number to the SVN revision.
  • With Subversion's atomic commits, make it clear which code was used for each debug/release build etc.
  • Automatic incrementing of the build number.
Googling showed a few tools to update the AssemblyInfo.cs file but this is a bit hard. The solution I used in the end was:
  • Auto-generate one AssemblyInfo.cs file using Tigris MSBuild community tasks project target for the solution (product).
  • All projects include that AssemblyInfo.c file by reference. Hence all assemblies have the same build number.
  • To make sure that the AssemblyInfo.cs file is generated first it a "Common" project was added to the solution with dependencies to ensure it would build first. Right now it does not have any source files, it just builds the AssemblyInfo.cs file.
  • Added the generated AssemblyInfo.cs file to Subversion's ignore list. This avoids the file appearing as changed in all projects.

No comments: