This project is read-only.

Instructions


1. Download MSBuildVersioning.dll and save it into your solution folder. It doesn't matter where - you can put it in the root folder of your solution, or you might already have a folder for third-party DLLs.

2. In your C# project's Properties folder, create files VersionInfo.base.cs and VersionInfo.cs.

3. Add the following lines to VersionInfo.base.cs (leave VersionInfo.cs empty).

using System.Reflection;
[assembly: AssemblyVersion("1.0.$REVNUM$.$DIRTY$")]
When your project builds, VersionInfo.base.cs will be copied over top of VersionInfo.cs, with $REVNUM$ replaced by your revision number and $DIRTY$ replaced with 1 if you have uncommitted changes, or 0 if the working copy is clean. See what other tokens you can use.

4. Make your source control include VersionInfo.base.cs and ignore VersionInfo.cs.

5. Set the "Build Action" to None for VersionInfo.base.cs and Compile for VersionInfo.cs.

VersionInfoBase.png

6. Remove the AssemblyVersion and AssemblyFileVersion lines from your project's AssemblyInfo.cs.

7. Close your solution, and open your project's csproj file in a text editor. At the bottom of the file, uncomment the BeforeBuild and AfterBuild targets. Add the following UsingTask and HgVersionFile elements:

  <UsingTask TaskName="HgVersionFile" AssemblyFile="..\MSBuildVersioning.dll" />
  <Target Name="BeforeBuild">
    <HgVersionFile TemplateFile="Properties\VersionInfo.base.cs"
        DestinationFile="Properties\VersionInfo.cs" />
  </Target>
  <Target Name="AfterBuild">
  </Target>
</Project>
  • If you're using Subversion, replace HgVersionFile with SvnVersionFile.
  • "..\MSBuildVersioning.dll" assumes you put MSBuildVersioning.dll in the root folder of your solution. Adjust this path if you put it somewhere else.

8. Reopen your solution, and build!

Last edited Jun 30, 2010 at 3:13 PM by jdaley, version 6

Comments

No comments yet.