This requires Microsoft Visual Studio 2012 SDK and Microsoft Visual Studio 2012 Visualization & Modeling SDK, which come separately from Visual Studio 2012. Other version combinations are probably possible, and maybe compatible, but untested. The core of the method is this:
- Add AssemblyInfo.tt to
MyProject\Properties
, filling out the "Your xxxxxx" sections. - Open up the project file (e.g.
MyProject.csproj
) in a text editor (e.g. Notepad++), and locate the line that defines the build targets for the language ("import project... microsoft.csharp.targets") - Insert the contents of
MyProject.csproj
there - Finally, if you build the
AssemblyInfo.tt
template within Visual Studio, make sure to setAssemblyInfo1.cs
toBuild Action: None
in the File Properties window. This will fix any errors about duplicate definitions.
Now, when building in the Release configuration, the third part of the version number is incremented and the fourth reset; when building in any other configuration, the fourth part of the version number is incremented.
To force a version bump, edit the AssemblyInfo.cs
file directly, setting the numbers to the version you want;
the templater will automatically increment from where you put it from that point onward.
A simpler alternative is to use Microsoft's default version "incrementing": edit the existing AssemblyInfo.cs
file
and remove the AssemblyFileVersion line, then edit the AssemblyVersion line to: [assembly: AssemblyVersion("M.m.*")]
where M and m are your major and minor version respectively. This will generate a version number like
1.3.3912.482
where the third part is the number of days since 2000-01-01, and the fourth part is half the number
of seconds since midnight.