Click here to Skip to main content
13,402,795 members (41,298 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


55 bookmarked
Posted 12 May 2010

Autoincrement Version in Visual Studio

, 12 May 2010
Rate this:
Please Sign up or sign in to vote.
Autoincrement version in Visual Studio


This is a small application with source code provided. It helps organize version auto increment in C# projects.

Using the Code


vbinc -[af1234]|[-c]|[-h]


  • a Increment assembly version
  • f Increment file version
  • 1 Increment +1.x.x.x (Increments major version)
  • 2 Increment x.+1.x.x (Increments minor version)
  • 3 Increment x.x.+1.x (Increments build)
  • 4 Increment x.x.x.+1 (Increments revision)
  • c Just show current version
  • h this help screen.


vbinc -af34

Increments assembly and file build and revision numbers.

C# has version format like [major version].[minor].[build].[revision]

  • Put vbinc.exe to the root of solution
  • Put lines
if  $(ConfigurationName) == Debug $(ProjectDir)vbinc.exe -af4
if  $(ConfigurationName) == Release $(ProjectDir)vbinc.exe -af34

or if your path contains a space character, try enclosing the $(ProjectDir) in quotes

if  $(ConfigurationName) == Debug "$(ProjectDir)"vbinc.exe -af4
if  $(ConfigurationName) == Release "$(ProjectDir)"vbinc.exe -af34

to Pre-Build event command line of each project.

From now, every Debug build will increment [revision] of assembly and file before build of project.

And every Release build will increment [build] and [revision] of assembly and file.

using System;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;

namespace vbinc
    class Program
        private static int _incMajor = 0;
        private static int _incMinor = 0;
        private static int _incRevno = 0;
        private static int _incBuild = 0;

        private static bool _bshow;
        private static bool _bassemply;
        private static bool _bfile;

        private const string Pattern1 = 
                    @"\[assembly\: AssemblyVersion\
        private const string Pattern2 =
                    @"\[assembly\: AssemblyFileVersion\

        private const string VersionFile = @"..\..\Properties\AssemblyInfo.cs";
        private const string BackupFile = @"..\..\Properties\AssemblyInfo.~cs";

        static void Main(string[] args)

                string str = File.ReadAllText(VersionFile);
                string result;                

                if (_bassemply || _bshow) result = GetResult
			(Pattern1, str, "AssemblyVersion");
                else result = str;
                if (_bfile || _bshow) result = GetResult
			(Pattern2, result, "AssemblyFileVersion");

                if (!_bshow)
                    File.Copy(VersionFile, BackupFile);
                    File.WriteAllText(VersionFile, result);
            catch (Exception ex)
                Console.WriteLine("ERR: " + ex.Message);

        private static void forDebug()

        public static bool ParseCmdLine(string[] args)
            if (args.Length == 0) return false;
            string astr;

            foreach (string arg in args)
                    astr = arg.ToLower();
                    if (astr.Contains("a")) _bassemply = true;
                    if (astr.Contains("f")) _bfile = true;
                    if (astr.Contains("1")) _incMajor = 1;
                    if (astr.Contains("2")) _incMinor = 1;
                    if (astr.Contains("3")) _incBuild = 1;
                    if (astr.Contains("4")) _incRevno = 1;
                    if (astr.Contains("c")) _bshow = true;

                if (arg.ToLower().StartsWith("-h")) return false;

                if (_bshow)
                    _incMajor = 0;
                    _incMinor = 0;
                    _incBuild = 0;
                    _incRevno = 0;
            return true;

        public static void ShowUsage()
            Console.WriteLine("vbinc v{0}", 

            Console.WriteLine("Autoincrement version in c# projects. by");
            Console.WriteLine("usage: vbinc -[af1234]|[-c]|[-h]");
            Console.WriteLine("\t-a Increment assembly version");
            Console.WriteLine("\t-f Increment file version");
            Console.WriteLine("\t-1 Increment +1.x.x.x");
            Console.WriteLine("\t-2 Increment x.+1.x.x");
            Console.WriteLine("\t-3 Increment x.x.+1.x");
            Console.WriteLine("\t-4 Increment x.x.x.+1");
            Console.WriteLine("\t-c Just show current version");
            Console.WriteLine("\t-h this help screen.");
            Console.WriteLine("Example: vbinc -af34");
            Console.WriteLine("Increments assembly and file build and revision numbers.");



        private static string GetResult(string pattern, string str, string app)
            Regex r = new Regex(pattern);
            Match m = r.Match(str);

            string rz = string.Format("[assembly: {4}(\"{0}.{1}.{2}.{3}\")]"
                , GetInc(m.Groups[1].Value, _incMajor)
                , GetInc(m.Groups[2].Value, _incMinor)
                , GetInc(m.Groups[3].Value, _incBuild)
                , GetInc(m.Groups[4].Value, _incRevno)
                , app);


            return r.Replace(str, rz);

        private static int GetInc(string aVer, int adoInc)
            return Convert.ToInt32(aVer) + adoInc;


  • 12th May, 2010: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Lithuania Lithuania
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionNo visible action taken Pin
barriesargent23-May-14 7:41
memberbarriesargent23-May-14 7:41 
SuggestionPre-build Pin
kptkachenko6-Feb-14 20:41
memberkptkachenko6-Feb-14 20:41 
GeneralMy vote of 4 Pin
Ali Taghvajou19-Jan-13 20:04
memberAli Taghvajou19-Jan-13 20:04 
GeneralRe: My vote of 4 Pin
Andy Neillans3-Jan-14 22:01
memberAndy Neillans3-Jan-14 22:01 
QuestionError.. Pin
Yukiiii2-Aug-11 14:47
memberYukiiii2-Aug-11 14:47 
AnswerRe: Error.. Pin
vdasus3-Aug-11 0:11
membervdasus3-Aug-11 0:11 
AnswerRe: Error.. Pin
Joe Pizzi20-Sep-11 17:43
memberJoe Pizzi20-Sep-11 17:43 
GeneralRe: Error.. Pin
vdasus20-Sep-11 22:14
membervdasus20-Sep-11 22:14 
GeneralCant have it working... Pin
henur22-Oct-10 22:45
memberhenur22-Oct-10 22:45 
GeneralRe: Cant have it working... Pin
vdasus25-Oct-10 8:14
membervdasus25-Oct-10 8:14 
GeneralNice work Pin
Donsw5-Jun-10 17:23
memberDonsw5-Jun-10 17:23 
Generalnew version releaseed :) Pin
vdasus26-May-10 1:54
membervdasus26-May-10 1:54 
Autoincrement build version, using vcs (bazaar plugin included)[^]

vbinc2 v1.0.14.35
Autoincrement version in projects. Copyright 2010 (c)
usage: vbinc [-v<wxyz>] [-p<path to file>] [-r<regexp>] [-n]|[-i]|[-c]|[-h]|[-e]
-h help screen.

-v<wxyz> Increment version, where:
w=major, x=minor, y=build, z=revision incrementors
May be signed number or letter of plugin id
-p Set path to file with version. [..\..\Properties\AssemblyInfo.cs]
-r Set regexp to extract version.
[\[assembly\: AssemblyVersion\("(\d+)\.(\d+)\.(\d+)\.(\d+)"\)\]
-n Increment number from plugin by one. [NO]
-i Show available plugins with id
-c Show current version
-e Show examples
GeneralRe: new version releaseed :) Pin
Robin1-Jun-10 8:59
memberRobin1-Jun-10 8:59 
GeneralRe: new version releaseed :) Pin
vdasus1-Jun-10 9:31
membervdasus1-Jun-10 9:31 
GeneralHas anyone tried this on a C++/CLI or C++/MFC Project Pin
MicroImaging13-May-10 5:26
memberMicroImaging13-May-10 5:26 
GeneralRe: Has anyone tried this on a C++/CLI or C++/MFC Project Pin
vdasus13-May-10 6:24
membervdasus13-May-10 6:24 
GeneralRe: Has anyone tried this on a C++/CLI or C++/MFC Project Pin
vdasus26-May-10 1:56
membervdasus26-May-10 1:56 
GeneralLooks interesting Pin
supercat912-May-10 12:47
membersupercat912-May-10 12:47 
GeneralRe: Looks interesting Pin
vdasus12-May-10 22:33
membervdasus12-May-10 22:33 
GeneralRe: Looks interesting Pin
supercat913-May-10 6:15
membersupercat913-May-10 6:15 
GeneralRe: Looks interesting Pin
vdasus13-May-10 6:22
membervdasus13-May-10 6:22 
GeneralRe: Looks interesting Pin
vdasus26-May-10 1:52
membervdasus26-May-10 1:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1802120.2 | Last Updated 12 May 2010
Article Copyright 2010 by vdasus
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid