How to change Assembly Version Number using AssemblyInfoTask?

Chetan picture Chetan · Dec 30, 2010 · Viewed 41k times · Source

I am trying to automate the process for setting the Version for all DLL's, after spending some time I came to know the AssemblyInfo Task with which it can most likely be achieved.

So I went ahead and installed it, specifically version 1.0.51130.0.

After Installing, I manually added the Import Tag (by unloading the each project) of AssemblyInfoTask in .cspoj files (the solution has more than 35 proj files).

<Import Project="$(MSBuildExtensionsPath)\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.Targets"/>

Next I modified the Microsoft.VersionNUmber.Target file which will be installed in path: C:\Program Files\MSBuild\Microsoft\AssemblyInfoTask, and I modified the following section:

<!-- Properties for controlling the Assembly Version -->
<PropertyGroup>
    <AssemblyMajorVersion>4</AssemblyMajorVersion>
    <AssemblyMinorVersion>0</AssemblyMinorVersion>
    <AssemblyBuildNumber></AssemblyBuildNumber>
    <AssemblyRevision></AssemblyRevision>
    <AssemblyBuildNumberType>DateString</AssemblyBuildNumberType>
    <AssemblyBuildNumberFormat>01MMdd</AssemblyBuildNumberFormat>
    <AssemblyRevisionType>AutoIncrement</AssemblyRevisionType>
    <AssemblyRevisionFormat>00</AssemblyRevisionFormat>
</PropertyGroup>

<!-- Properties for controlling the Assembly File Version -->  
<PropertyGroup>
    <AssemblyFileMajorVersion>4</AssemblyFileMajorVersion>
    <AssemblyFileMinorVersion>0</AssemblyFileMinorVersion>
    <AssemblyFileBuildNumber></AssemblyFileBuildNumber>
    <AssemblyFileRevision></AssemblyFileRevision>
    <AssemblyFileBuildNumberType>DateString</AssemblyFileBuildNumberType>
    <AssemblyFileBuildNumberFormat>01MMdd</AssemblyFileBuildNumberFormat>
    <AssemblyFileRevisionType>AutoIncrement</AssemblyFileRevisionType>
    <AssemblyFileRevisionFormat>00</AssemblyFileRevisionFormat>
</PropertyGroup>

Next I set the assemblyInfo.cs file's version to 1.0.0.0 in every project. Finally I saved and close it, reopened solution, and built. It works like a champ!

Now what want is to customize the Version to 4.0.1053.1 where 10 is the part of year indicator which is 2010 and 53 denotes the week number, at last 1 denotes revision number.

How to achieve this using the AssemblyInfo Task? I came across several posts that a new version of AssemblyInfo Task is available in Build Extension Pack.

I have installed the MSBuild Extension Pack December 2010 and its version is MSBuild Extension Pack 4.0.2.0 Installer

Answer

James Woolfenden picture James Woolfenden · Feb 11, 2011

First.. use a globalassemblyinfo.cs that is linked from each project. Add its as linked file to each project. This means you update one file, not 30+ assemblyinfo files...then:

use MSBuild.Community.Tasks....

Then call

<AssemblyInfo CodeLanguage="CS"
         OutputFile="$(VersionFile)"
         AssemblyCompany="Company"
         AssemblyProduct="Product"
         AssemblyCopyright="Copyright © Company 2011"
         ComVisible="false"
         AssemblyVersion="$(BUILD_NUMBER)"
         AssemblyFileVersion="$(BUILD_NUMBER)" />

Assuming you have something like:

<Import Project=".\tasks\MSBuild.Community.Tasks.Targets"/>