Click here to Skip to main content
15,392,955 members
Articles / Programming Languages / C#
Posted 27 May 2010

Tagged as


7 bookmarked

Autoincrement Build Version, Using VCS (bazaar plugin included)

Rate me:
Please Sign up or sign in to vote.
4.20/5 (3 votes)
27 May 2010CPOL3 min read
Autoincrement build version with possibility of using VCS


I decided to rewrite an autoincrement program. Second version. What's the differences? It does not depend on the environment (you can use with f.e. Visual Basic project, and indeed for all, which version is stored in a file. So a few words on the resulting utility, and then about the beauty of .NET 4. I'm a novice in .NET, and I'll be grateful for any advice.


Utility is a program and plugin. You can easily write the plugins by yourself, following the example. I use the bazaar, which I highly recommend. For it is already written plugin.

You can use this utility to automatically increment version of assembly or file with each rebuild.

Using the Code

The standard version in .NET is

Each plugin of utility has its own one-letter identifier (not digital). This is done to simplify using.

  • I can write vbinc2.exe-v0001 - increase only revision.
  • I can write vbinc2.exe-v0011 - will increase and build and revision
  • I can write vbinc2.exe-v001-1 - will increase by 1 build, and revision will decrease by one.

Now about plugins. For instance, if I have near to EXE plugin for bazaar, with id equals to "b" - I can write: vbinc2.exe-v00b1. In this case, build will be taken from the plugin with id "b" (number of current revision), i.e. if the current revision is 5 - build will always be 5 (so far we do not commit to the next revision) and the revision will increase by 1.

You can write a couple of plugins as you like and use them as: vbinc2.exe-v00bc.

Then the build is taken from one plugin, and revision from another with id="c"...

So what do we have with the code ...First is organization of plugin subsystem. .NET 4 has inside built-in subsystem for working with plugins.

All that is necessary to describe the interface is to insert one attribute and a couple of options:

First - declaring interface:

public interface IVbinc2Sdk
    string Id { get; }
    string Name { get; }
    string Description { get; }
    int GetData();

Then implementing it (don't forget Export Attribute):

public class Vbinc2Bzr : IVbinc2Sdk
    private readonly string _id = "b";
    private readonly string _name = "Bazaar";
    private readonly string _desc = "Bazaar vcs plugin";
    private static readonly StringBuilder GetOutput = new StringBuilder("");
    public int GetData()

And main implementation:

//Add two lines and reference to System.ComponentModel.Composition
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
//Add Import attribute
    class Program
        protected IVbinc2Sdk[] Plugins { get; set; }
//Main method
        static void Main(string[] args)
                Program p = new Program();
        private void Run(string[] args)
            Compose(); // and do what you want else         
//Composing plugins from current directory 
        private void Compose()
            var catPlugs = new AggregateCatalog();
            catPlugs.Catalogs.Add(new DirectoryCatalog(
            var contPlugs = new CompositionContainer(catPlugs);
//And plugins using:
        private void ShowPlugins()
            foreach (IVbinc2Sdk plugin in Plugins)
                Console.WriteLine("--- Plugin: {0} ---", plugin.Name);
                Console.WriteLine("{0}", plugin.Description);
                Console.WriteLine("id: {0}", plugin.Id);
//That's all! It's enough to do lines above and you have
//normal plugin subsystem. You can make another plugin, put it to 
//directory near exe and plugin automatically available in your

You can see the project with the full source code and bins in attached zip.

You can specify the key -n - then taken from the plugin number will be incremented ...

To view the help -h

To see examples -e

How to use: F.e. you can create a folder in the root of solution /_v/ and put in 3 files:

  • vbinc2bzr.dll
  • vbinc2sdk.dll
  • vbinc2.exe

Each projects pre-build actions:

if $(ConfigurationName) == Release $(SolutionDir)\_v\vbinc2.exe -v00b1 -n 

if $(ConfigurationName) == Release $(SolutionDir)\_v\vbinc2.exe -v00b1 -n 
	-r"\[assembly\: AssemblyFileVersion\(""(\d+)\.(\d+)\.(\d+)\.(\d+)""\)\]" 

That's all. Now after each rebuild of release version build will be taken from bazaar current revision, and .NET revision will be incremented.


  • In regexp (if you write them yourself) - must be (\d+)\.(\d+)\.(\d+)\.(\d+). They are replaced by the version. Ugly ...
  • You have to write regexp for NOT C# projects. It's easy, but not everyone can outright. I strongly recommend to learn regexps ...
  • Written in a couple of hours, so no comments or properly thought-out.
  • In some configurations, bazaar plugin does not work on network drives (I think, plugin does not correctly take revision) - must try


  • It's working...

Thank you for your time and sorry for my English.


  • 27th 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

Comments and Discussions

GeneralThank you Pin
pv@dbpro.cz25-Feb-11 23:21
Memberpv@dbpro.cz25-Feb-11 23:21 
Generalok article Pin
Donsw3-Jun-10 10:18
MemberDonsw3-Jun-10 10:18 
well done. thanks for sharing.
My Recent Article : CDC - Change Data Capture

GeneralRe: ok article Pin
vdasus3-Jun-10 10:23
Membervdasus3-Jun-10 10:23 

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.