Surendra Sharma

Surendra Sharma

Search This Blog

Friday, June 14, 2013

How to Auto Increment Build/Version Numbers of Visual Studio Project and get in C#

Open "AssemblyInfo.cs"

Version information for an assembly consists of the following four values:

      Major Version
      Minor Version
      Build Number
      Revision

You can specify all the values or you can default the Revision and Build Numbers
by using the '*' as shown below:

Replace line
[assembly: AssemblyVersion("1.0.0.0")]
with
[assembly: AssemblyVersion("1.0.*")]

Remove or comment out below line
[assembly: AssemblyFileVersion("1.0.0.0")]

Here 1.0.0.0 Means [Major].[Minor].[Build].[Revision],

Now you should get new version number after each time you rebuild project.
C# code to get version number

var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
Label1.Text = string.Format("v{0}.{1}.{2} ({3})", version.Major, version.Minor, version.Build, version.Revision);

When to change each number?
  • Major number when a core piece of the app is rewritten or reworked.
  • Minor version when a new work order is processed
  • Auto increament or leave the build number at zero,
  • Auto increment the revision number every round of testing

In case of auto increament,

  • Build number is the number of days since Dec 31, 1999. 
  • The Revision number is the number of seconds since midnight, divided by 2.

2 comments:

  1. Hi Alex!
    After fruitlessly searching the Internet I finally stumbled acrros your perfect solution for the automated versioning of my Visiual Studio projects.
    Thank you!
    Jacques - The Netherlands

    ReplyDelete
    Replies
    1. You are always welcome my friend Jacques

      Delete