This project is read-only.

Instructions for Git Users

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 Git 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.

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 GitVersionFile elements:

  <UsingTask TaskName="GitVersionFile" AssemblyFile="..\MSBuildVersioning.dll" />
  <Target Name="BeforeBuild">
    <GitVersionFile TemplateFile="Properties\VersionInfo.base.cs"
        DestinationFile="Properties\VersionInfo.cs" />
  <Target Name="AfterBuild">
  • "..\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!

What Next?

  • You can customize your version format by using different tokens in VersionInfo.base.cs.
  • You can embed Git information into other parts of your program, such as your About dialog.


You will need to have git.exe on your path. If you don't have that, you may want to install Git for Windows and enable the "Run Git from the Windows Command Prompt" option.

Last edited Jul 25, 2010 at 6:57 AM by jdaley, version 1


bambams Aug 16, 2013 at 10:35 PM 
This doesn't seem to work with Git... I get «The "GitVersionFile" task could not be loaded from the assembly path\to\MSBuildVersioning.dll. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.» The DLL is versioned Is the Git task not in the binary release yet? Thanks.