Click here to Skip to main content
Click here to Skip to main content

XAutobuild - A utility to increment build number

, 6 Jun 2007 CPOL
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.

Introduction

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:

#ifndef AUTOBUILD_H
#define AUTOBUILD_H

// change the FALSE to TRUE for autoincrement of build number
#define INCREMENT_VERSION TRUE
#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>

VS_VERSION_INFO VERSIONINFO
  FILEVERSION FILEVER
  PRODUCTVERSION PRODUCTVER
  FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
  FILEFLAGS 0x1L
#else
  FILEFLAGS 0x0L
#endif
  FILEOS 0x4L
  FILETYPE 0x1L
  FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "E-mail", "hdietrich@gmail.com\0"
            VALUE "Article", "www.codeproject.com\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
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END
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:

screenshot

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

screenshot

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.

Alternatives

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.

screenshot

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

Usage

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.



License

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

Share

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 www.hdsoft.org.






Comments and Discussions

 
QuestionSubversion integration instead of autoupdating??? PinmemberCurtis J27-Sep-08 8:52 
GeneralStudio 2005 Pinmemberjung-kreidler1-Feb-08 4:22 
GeneralIt works well, thanks! Pinmemberoliverzy29-Jun-07 22:43 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 6 Jun 2007
Article Copyright 2007 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid