Versioning of .NET assemblies

I use four-parts version pattern that looks like: {Major}.{Minor}.{Date (MMdd)}.{Build Number}

An example version in this format would look like: 1.7.1028.37, which breaks down into being the first major release, seventh minor release, built on 28 October, and has been the 37th build for v1.7. Every time assembly is rebuild build counter increases.


Sample solution is available for download here

Version numbers in AssemblyInfo.cs file must be set before the assembly is build by continues integration system. Then an assembly will have exactly that version we need.

The meta information about a project including its version information is stored in AssemblyInfo.cs:

.NET framework provides opportunity to set two different types of version numbers to each assembly. The difference between AssemblyVersion and AssemblyFileVersion is described in this article “How to use Assembly Version and Assembly File Version“. At least AssemblyVersion number must be used for versioning. Both version numbers will be useful for a framework assembly which is used by other developers and is build frequently. Then assembly file should be updated after each build but library functionality may stay unchanged.

To set the version numbers we can use MSBuild Extension Pack.

– Install MSBuild Extension pack NuGet package to the solution
Install-Package MSBuild.Extension.Pack

– Add project build file to the solution
If there is no MSBuild project file there yet add it. Let’s call this file Build.proj

– Add a target to the build file that will change version number
MSBuild Extension has a special set of targets to manipulate with assemblies info – AssemblyInfo. Here is a target that will set AssemblyVersion and AssemblyFileVersion according to the four-numbers pattern: {Major version}.{Minor version}.{Date (MMdd)}.{Build Number} for all AssemblyInfo.cs files in the project.

– Run this target before sources are compiled
Here is an example Buil.proj file that has 4 basic steps: clean solution, restore packages, then do versioning, and at last build application step. Script is compatible with both MSBuild and xbuild and can be build on Windows and Linux using both .NET and Mono. Read more about restoring packages and other build steps in my post about building and testing.


Let’s build the project. Note that on Windows MSBuild is not in PATH by default. Then to build application from command line a “Developer Command Prompt for VS2012” should be used.

After the build is complete version numbers AssemblyInfo.cs are changed

Changes in AssemblyInfo.cs file should not be committed to CVS. Since these changes are normally done on CI-server it is not a problem.

Build binary has the right version number [assembly: AssemblyVersion("1.0.1105.003")]


External links about versioning: