Click here to Skip to main content
13,355,335 members (67,494 online)
Click here to Skip to main content
Add your own
alternative version


39 bookmarked
Posted 6 Jun 2007

XAutobuild - A utility to increment build number

, 6 Jun 2007
Rate this:
Please Sign up or sign in to vote.
XAutobuild auto-increments the build number contained in Autobuild.h. This can be used in resource files to automatically update the version resource each time a project is compiled.


For many years I have been using Autobuild.dll VS6 add-in written by Navi Singh, who got the inspiration for his add-in from the Microsoft Knowledge Base article (recently updated) How to increment version information after each build in Visual C++.

The way Singh's add-in works is by auto-incrementing build number contained in file Autobuild.h:


// change the FALSE to TRUE for autoincrement of build number
#define FILEVER        1,0,0,4
#define PRODUCTVER     1,0,0,4
#define STRFILEVER     "1, 0, 0, 4\0"
#define STRPRODUCTVER  "1, 0, 0, 4\0"

#endif //AUTOBUILD_H
Note: build number is last of the four numbers comprising the version number; in above example, build number is 4. XAutobuild does not modify other three numbers - you must manually edit Autobuild.h to change them. See below for more on version number nomenclature.

To disable the version auto-increment, you can define INCREMENT_VERSION as FALSE.

Autobuild.h can then be included in the resource file and used in the version resource:

// Version
#include <span class="code-string">"Autobuild.h"</span>

#ifdef _DEBUG
    BLOCK "StringFileInfo"
        BLOCK "040904b0"
            VALUE "E-mail", "\0"
            VALUE "Article", "\0"
            VALUE "FileDescription", "XAutobuild utility\0"
            VALUE "FileVersion", STRFILEVER
            VALUE "LegalCopyright", "Copyright © 2007 Hans Dietrich\0"
            VALUE "OriginalFilename", "XAutobuild.exe\0"
            VALUE "ProductName", "XAutobuild\0"
            VALUE "ProductVersion", STRPRODUCTVER
    BLOCK "VarFileInfo"
        VALUE "Translation", 0x409, 1200
Note: The above version resource is included in XAutobuild.exe via XAutobuild.rc.

VS2005 Usage

Singh's VS6 add-in doesn't work in VS2005, and so I decided to port the concept to VS2005 by writing standalone utility to update Autobuild.h. The XAutobuild utility takes path to Autobuild.h as an argument, and can be integrated into VS2005 build process as a build event.

The one thing you must be careful of is when $(TargetDir) path contains spaces. In that case, you must enclose it in quotes. Because last character in $(TargetDir) is backslash, it must be escaped with another backslash:


To see what XAutobuild is doing, you can include the optional -v command line switch, which will write to VS2005 Output window:


Version Number Nomenclature

In this article I have been talking about incrementing the build number, which is the common term for the part of the version number that is incremented each time project is built. For example, in version string 1,5,0,214, "214" is what I have been referring to as the build number ("1" is major version, and "5" is minor version).

Microsoft describes this four-part version number somewhat differently. If you look at AssemblyInfo.cs, you will see this:

//    Major Version
//    Minor Version 
//    Build Number
//    Revision
which indicates that Microsoft considers the third value to be build number. If this is convention you wish to follow, it is easy enough to modify XAutobuild.


As I stated above, my purpose in writing XAutobuild is to provide the same functionality in VS2005 as Singh's Autobuild.dll VS6 add-in, and that meant reading and writing Autobuild.h in the same format as the VS6 add-in. This allows me to use the same Autobuild.h and the same .rc resource file in projects that are compiled for both VS6 and VS2005. By using a .rc resource file in .Net projects, I am able to add extra version strings, such as Article and E-mail, which I cannot do by using the standard AssemblyInfo.cs.


However, if you are not concerned with this VS6 backward compatibility, there are several other excellent articles here on CodeProject that offer different approaches to auto-incrementing the version number. Here are some (all rated above 4):

VS2005 Built-in Versioning

VS2005 has built-in a limited form of versioning. You can specify automatic version incrementing by using wildcard for build number in AssemblyInfo.cs. For example,
[assembly: AssemblyVersion("1.0.*")]
will cause build to be set to number of days since January 1, 2000, and revision to be set to number of seconds since midnight, divided by 2. Or you can specify
[assembly: AssemblyVersion("1.0.0.*")]
which will cause revision to be set to number of seconds since midnight, divided by 2. Wildcards do not have same effect for AssemblyFileVersion.

Revision History

Version 1.0 — 2007 June 6

  • Initial public release


This software is released into the public domain. You are free to use it in any way you like, except that you may not sell this source code. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.


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


About the Author

Hans Dietrich
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see

You may also be interested in...


Comments and Discussions

QuestionSubversion integration instead of autoupdating??? Pin
Curtis J27-Sep-08 8:52
memberCurtis J27-Sep-08 8:52 
GeneralAccessing the build number directly Pin
Halloko10-Aug-08 10:18
memberHalloko10-Aug-08 10:18 
GeneralStudio 2005 Pin
jung-kreidler1-Feb-08 4:22
memberjung-kreidler1-Feb-08 4:22 
GeneralIt works well, thanks! Pin
oliverzy29-Jun-07 22:43
memberoliverzy29-Jun-07 22:43 

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
Web04 | 2.8.180111.1 | Last Updated 6 Jun 2007
Article Copyright 2007 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid