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
#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:
#include "Autobuild.h"
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:
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:
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.
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
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.