How to update the build number in a .RC file every time I build?

I thought this was such a basic thing that it would be built into VS, or answered in a FAQ somewhere, but I can't find the answer.  What is the best way to increment the build number of my (non-managed) C++ exe

Answer this question

How to update the build number in a .RC file every time I build?

  • Spog Mog

    Thanks for your reply.  I would be very interested to hear from Microsoft if this is the way they do it, or the way they recommend.
  • The Aqua

    Hi hyslopc!
    Thanks for your reply.  I would be very interested to hear from Microsoft if this is the way they do it, or the way they recommend.
    The offical statement is:

    How To Increment Version Information After Each Build in Visual C++
    http://support.microsoft.com/kb/q237870/
    (at least for VC6)

    For VC2002/2003 you can find an example here:
    http://www.codeguru.com/Csharp/.NET/net_vs_addins/article.php/c5961/

    Currently I am not aware of an build-in build-number inrementer in VC2005 Beta2...
    -- 
    Greetings
     Jochen
     
      My blog about Win32 and .NET
      http://blog.kalmbachnet.de/

  • Marian Pascalau

    So Microsoft - what do you say   How do *you* update build numbers for all your thousands of C++ DLLs and EXEs when using VS 2005
  • Enggtp

    The problem with the links you provided is that are require that you build using Visual Studio. Therefore if you are going to use MSBuild to build your applications in the future, that's not going to work.

  • almargob

    I went searching a while back for a way to do this also, but found most solutions were macros within Visual Studio, which is obviously not ideal when building with MSBuild.

    So I wrote a simple command-line application that simply modifies an rc based on parameters passed to it.  It wouldn't be too hard to write a task to do the same thing.

    Here is an example that does it:


    string tempPath = Path.GetTempFileName();

     

    using (StreamReader reader = new StreamReader(inputPath, System.Text.Encoding.Default)){   using (StreamWriter writer = new StreamWriter(tempPath, false, reader.CurrentEncoding))   {

     

          string line;

     

          while ((line = reader.ReadLine()) != null)      {

     

             if (line.StartsWith(" FILEVERSION"))         {

     

                line = string.Format(CultureInfo.InvariantCulture, " FILEVERSION {0},{1},{2},{3}", version.Major, version.Minor, version.Build, version.Revision);

     

             }         else if (line.StartsWith(" PRODUCTVERSION"))         {            line = string.Format(CultureInfo.InvariantCulture, " PRODUCTVERSION {0},{1},{2},{3}", version.Major, version.Minor, version.Build, version.Revision);         }         else if (line.StartsWith(" VALUE \"FileVersion\""))         {

     

                line = string.Format(CultureInfo.InvariantCulture, " VALUE \"FileVersion\", \"{0}\"", version.ToString());         }         else if (line.StartsWith(" VALUE \"ProductVersion\""))         {            line = string.Format(CultureInfo.InvariantCulture, " VALUE \"ProductVersion\", \"{0}\"", version.ToString());         }

     

             writer.WriteLine(line);      }   }}

     

    File.Copy(tempPath, outputPath, true);
     



    Sorry for the hard to read code but these forums are terrible at formatting code.



  • eam0n

    Microsofts internal build process uses a system very similar to the one described in the articles posted.

    Since our processes are based around a "daily build" the version information that is stamped into DLLs and EXEs is controlled centrally and corresponds to the day that the build was done.

    We have a header file (used by RC files amongst others) that is generated by our build lab and checked into the tree. All DLLs and EXEs then just include a standard .RC that includes this header and gets the file information. Interestingly, here in the developer division we have two: one that represents the .NET Framework version and one that represents the Visual Studio version. Components then include the appropraite one.

    This process is exactly the same when using MSBuild and VCBuild.

    Automating the generation of the header file using MSBuild would be very straightforward - you could create a custom task that creates the file. Here's a link to how to create a custom task: http://channel9.msdn.com/wiki/default.aspx/MSBuild.ExtendMSBuildWithANewTask


    Hope that helps,

    Kieran Mockford
    MSBuild Team.



  • webmote

    Thanks, Kieran - very interesting.
  • How to update the build number in a .RC file every time I build?