user772913
user772913

Reputation: 63

Embed a build number / build ID into a project in Visual Studio 2008

There has been confusion a few times with my testers somehow getting old builds of my project to test, and then reporting on fixed bugs.

How can I embed a build ID into my project? Current time of build, or simply starting at 1 and incrementing every time the program is built would work. Then in the game UI, the build number will be printed so there is no ambiguity as to which version of the software the tester is using.

I've googled around for an answer and asked on IRC, but everything I've found seems to pertain only to C#.

Any ideas? On Unix, I would just modify the Makefile, and have some oneliner insert the value I need into the source.

Right now my best idea is to figure out how the VS build process works, then write a python script to run first and edit the source to update the build number.

Upvotes: 3

Views: 1319

Answers (2)

user772913
user772913

Reputation: 63

Ok, here is my quick and dirty and ugly solution.

I have a buildid.txt file, this is a text file with only an integer value for buildid.

I have increment-buildid.bat

@echo off
for /f %%a in (buildid.txt) do (
  echo %%a
  set /a num=%%a
)
echo %num%
set /a num += 1
echo %num% > buildid.txt
echo int buildid = %num%; > buildid.c

To muck about with the Visual Studio build process, right click solution in solution explorer, -> properties -> Build Events -> Pre-Build Events.

Now that I know how do do this, I can put in my zip + scp script in post build events for instant upload! (not sure of that's blocking or not, will have to test it)

edit: the upload is indeed blocking. that is, debugging does not start until the upload has finished. I just have another batch to upload using scp as I feel the need to. Double click it, and it is sent to remote server.

Upvotes: 3

Mark Tolonen
Mark Tolonen

Reputation: 177891

To solve the same problem, I wrote a small utility that generates a header file containing a date/time stamp in a #define. It runs as a pre-build step and the main project includes the generated header. Then you can include the stamp in a sign-on banner or the like.

In my projects I also generate a version resource, then move it into an .rc2 file (manually written resources) and modify it to include the generated header and update the version appropriately.

Upvotes: 2

Related Questions