Can I automatically increment the file build version when using Visual Studio? Can I automatically increment the file build version when using Visual Studio? asp.net asp.net

Can I automatically increment the file build version when using Visual Studio?


In visual Studio 2008, the following works.

Find the AssemblyInfo.cs file and find these 2 lines:

[assembly: AssemblyVersion("1.0.0.0")][assembly: AssemblyFileVersion("1.0.0.0")]

You could try changing this to:

[assembly: AssemblyVersion("1.0.*")][assembly: AssemblyFileVersion("1.0.*")]

But this won't give you the desired result, you will end up with a Product Version of 1.0.* and a File Version of 1.0.0.0. Not what you want!

However, if you remove the second of these lines and just have:

[assembly: AssemblyVersion("1.0.*")]

Then the compiler will set the File Version to be equal to the Product Version and you will get your desired result of an automatically increment product and file version which are in sync. E.g. 1.0.3266.92689


open up the AssemblyInfo.cs file and change

// You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below:// [assembly: AssemblyVersion("1.0.*")][assembly: AssemblyVersion("1.0.0.0")][assembly: AssemblyFileVersion("1.0.0.0")]

to

[assembly: AssemblyVersion("1.0.*")]//[assembly: AssemblyFileVersion("1.0.0.0")]

you can do this in IDE by going to project -> properties -> assembly information

This however will only allow you to auto increment the Assembly version and will give you the

Assembly File Version: A wildcard ("*") is not allowed in this field

message box if you try place a * in the file version field.

So just open up the assemblyinfo.cs and do it manually.


Another option for changing version numbers in each build is to use the Version task of MSBuild.Community.Tasks. Just download their installer, install it, then adapt the following code and paste it after <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> in your .csproj file:

<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" /><Target Name="BeforeBuild">    <Version VersionFile="Properties\version.txt" Major="1" Minor="0" BuildType="Automatic" StartDate="12/31/2009" RevisionType="BuildIncrement">      <Output TaskParameter="Major" PropertyName="Major" />      <Output TaskParameter="Minor" PropertyName="Minor" />      <Output TaskParameter="Build" PropertyName="Build" />      <Output TaskParameter="Revision" PropertyName="Revision" />    </Version>    <AssemblyInfo CodeLanguage="CS"                  OutputFile="Properties\VersionInfo.cs"                  AssemblyVersion="$(Major).$(Minor)"                  AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)" /></Target>

Note: Adapt the StartDate property to your locale. It currently does not use the invariant culture.

For the third build on January 14th, 2010, this creates a VersionInfo.cs with this content:

[assembly: AssemblyVersion("1.0")][assembly: AssemblyFileVersion("1.0.14.2")]

This file then has to be added to the project (via Add existing item), and the AssemblyVersion and AssemblyFileVersion lines have to be removed from AssemblyInfo.cs.

The different algorithms for changing the version components are described in $(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.chm and Version Properties.