joeware - never stop exploring... :)

Information about joeware mixed with wild and crazy opinions...

Auto Incrementing Build Versions for c++ applications in Visual Studio 2010

by @ 11:32 pm on 3/31/2011. Filed under tech

Visual Studio 2010 has been a bit annoying for me. Some basic things that Borland has done for years isn’t handled by the built in functionality.

The issue I dealt with tonight was auto incrementing the build numbers for the executables. Again, in Borland/CodeGear C++ Builder you simply go to the tab with the properties of the application (or DLL) and simply click a check box saying you want a version number, specify the version number, then click another check box saying you want auto-incrementing of build numbers.

Where is that in VS2010? Couldn’t find it. So then I look at third party VS extensions. I find a couple of them, I install each in turn, neither seems to work. I look at a KB article from MSFT which I had no intention of going through all of that work so then I just wrote a quick and dirty perl script to do it that I attach to the app build process through a Post-Build Build event in the property sheet for the app.

Here is the script with its q-n-d instructions on how to use

#
# Quick and Dirty Script to implement a basic feature that Visual Studio should have
# that Borland has had for at least 10 years… Auto Build Version Increment
#
# Note that if there are any unicode characters in the version resource script file
# they will be screwed up after this runs.
#
# To get Visual Studio to execute, add
#      perl f:\dev\perl\vsBuildIncrement\vsBuildIncrement.pl $(ProjectDir) quiet
# to the Property Page for the app under All Configurations and All Platforms
#
#

$path=shift;
$quiet=shift;

@out=`dir $path\\*.rc* /b`;
chomp @out;

foreach $thisfile (@out)
{
  $updated=0;
  $filepath=$path."\\".$thisfile;
  if (!$quiet) {print "Processing $filepath…\n"};
  @file=`type $filepath`;
  map 
   {
    $thisline=$_;

    # FILEVERSION
    #  FILEVERSION 1,0,0,0
    if ($thisline=~/(.+)FILEVERSION (\d+),(\d+),(\d+),(\d+)/)
     {
      $newline=$1."FILEVERSION $2,$3,$4,".($5+1)."\n";
      if (!$quiet)
       {
        print "Replace\n";
        print "   $thisline";
        print "with\n";
        print "   $newline";
       }
      $updated=1;
      $_=$newline;
     }    

    # FileVersion
    #              VALUE "FileVersion", "1.0.0.0"
    if ($thisline=~/(.+)VALUE \"FileVersion\", \"(\d+).(\d+).(\d+).(\d+)\"/)
     {
      $newline=$1."VALUE \"FileVersion\", \"$2.$3.$4.".($5+1)."\"\n";
      if (!$quiet)
       {
        print "Replace\n";
        print "   $thisline";
        print "with\n";
        print "   $newline\n";
       }
      $updated=1;
      $_=$newline;
     }    

   } @file;

  if ($updated)
   {
    open OFH,">$filepath";
    print OFH @file;
    close OFH;
   }

}

Rating 4.00 out of 5

Comments are closed.

[joeware – never stop exploring… :) is proudly powered by WordPress.]