For many years I have been using
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:
#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"
Note: build number
is last of the four numbers
comprising the version number; in above example, build
number is 4.
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
Autobuild.h can then be included in the resource file and used in the
#include <span class="code-string">"Autobuild.h"</span>
VALUE "E-mail", "email@example.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
VALUE "Translation", 0x409, 1200
Note: The above version resource is included in
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
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
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
, "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:
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
As I stated above, my purpose in writing
is to provide the same functionality in VS2005 as Singh's
VS6 add-in, and that meant reading and writing
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
, which I cannot do by using the standard
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,
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
which will cause revision to be set
to number of seconds since midnight, divided by 2. Wildcards do not have
same effect for
Version 1.0 — 2007 June 6
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.