.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Programming (http://forums.bots-united.com/forumdisplay.php?f=25)
-   -   Build number (http://forums.bots-united.com/showthread.php?t=2384)

koraX 30-07-2004 11:47

Build number
 
What is the best way to record build number of your program in MSVC ?

I think build number stands for how many times you have build your project. It is stated in some programs, like version 3.4, build 1234. IMHO it is better than date, 'cause it is automatical and it is also good for you to not lost in your project.

So anyb knows how to do it ? Or is there some option in MSVC which does that for you ? I once made some program which increased some number in file, and was executed everytime i pressed build in MSVC. But i think there is a better way to do it.

botman 30-07-2004 21:33

Re: Build number
 
"I once made some program which increased some number in file, and was executed everytime i pressed build in MSVC. But i think there is a better way to do it."

I think that is the only way to have an automated build version number. Visual Studio doesn't have this as a built in feature.

You could make a batch file that creates a .h file with the version number in it, then include that .h file in your source code when building the executable. The problem with this is that MSVC will always want to rebuild the executable each time that .h file it changed (because the date of the .h file is more recent than the date of the .exe file since the custom build steps only run AFTER the .exe file has been generated). You will need to set the date of the .h file back to BEFORE the date of the .exe (or the .cpp files). You can create a little utility that generates this .h file and sets the modification date/time back to something in the past (before the .cpp and .exe files).

botman

Whistler 31-07-2004 03:41

Re: Build number
 
or use this one, which is adapted from the Quake source code:
Code:

unsigned short CGeneral::GetBuildNumber()
{
  const char *date = __DATE__;

  char *mon[12] =
  { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  unsigned char mond[12] =
  { 31,    28,    31,    30,    31,    30,    31,    31,    30,    31,    30,    31 };

  int m = 0, d = 0, y = 0;

  for (m = 0; m < 11; m++) {
      if (strncmp(&date[0], mon[m], 3) == 0)
        break;
      d += mond[m];
  }

  d += atoi( &date[4] ) - 1;
  y = atoi( &date[7] ) - 2000;

  unsigned short usBuildNumber = d + (int)((y - 1) * 365.25);

  // Is it a leap year?
  if ((y % 4) == 0 && m > 1) {
      usBuildNumber += 1;
  }

  return usBuildNumber - 1267;
}


koraX 02-08-2004 19:06

Re: Build number
 
I made my own program which will increase build number and store date and time of the last build in xml file. It also has history of all builds.

Program also creates .h file, so you can use build number/date/time in your program. It supports multi-project workspace/solution and several configurations (debug/release)

It can be easily implemented in MSVC .NET, because .NET has pre-build setup. So it will launch before compiling, so no problems with time attributes for .h file. You just have to compile it and add this to pre-build line of your program :
$(SolutionDir)buildnum.exe $(SolutionDir)build.xml $(SolutionName) $(ProjectName) $(ConfigurationName) ..\path\to\h\build.h

program is very simple, one .cpp file. Download it here

It is also using my XML parser, so it is good as an example for it.


resulting xml file can look like this :
Code:

<?xml version="1.0" encoding="UTF-8" ?>
<kXBot>
        <kXBotdll>
                <debug>
                        <latest>
                                <build>4</build>
                                <date>02.08.2004</date>
                                <time>13:49</time>
                        </latest>
                        <history>
                                <build date="02.08.2004" time="13:49">4</build>
                                <build date="01.08.2004" time="11:33">3</build>
                                <build date="31.07.2004" time="23:10">2</build>
                                <build date="31.07.2004" time="15:14">1</build>
                        </history>
                </debug>
                <release>
                        <latest>
                                <build>2</build>
                                <date>02.08.2004</date>
                                <time>14:00</time>
                        </latest>
                        <history>
                                <build date="02.08.2004" time="14:00">2</build>
                                <build date="01.08.2004" time="10:11">1</build>
                        </history>
                </release>
        </kXBotdll>
</kXBot>

and .h file :
Code:

// koraXs build number logger 1.0
// Copyright (c) 2004, Jozef Wagner, http://neuron.tuke.sk/~wagner jowag@szm.sk

// This file is automatically generated, do not edit !

#define BUILD_NUMBER 2
#define BUILD_DATE "02.08.2004"
#define BUILD_TIME "14:00"

btw the code tag in this forum is somewhat broken, it adds one space at the begining, so first line is shifted

stefanhendriks 02-08-2004 19:13

Re: Build number
 
euhm, i just manually update the build number. This is because i do not want it to be increased everytime i compile (build) something. THis is insane, sometimes i fix something and hit build to verify...

koraX 02-08-2004 19:19

Re: Build number
 
I did that too but my lazyness caused that I quite early lost track of my program versions, as I backup them a lot.

And I usually code in debug mode and switch to release when I think I done everything I wanted


All times are GMT +2. The time now is 01:02.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.