Click here to Skip to main content
15,860,859 members
Articles / Desktop Programming / MFC
Article

Auto-Incrementing Build Numbers

Rate me:
Please Sign up or sign in to vote.
4.89/5 (13 votes)
8 Mar 2000 144.3K   2.2K   64   25
Describes a way to automatically generate an application build number.
  • Download demo project - 35 Kb

    Updated: 09 Mar 2000. See below for updates.

    This code increments the version number on each build.

    After including the autobuild.dll as an Add-In for dev studio, the following happens. When you do a build, a file autobuild.h is created/updated in your project's folder.

    If you want to increment your version number with each build, set the flag INCREMENT_BUILD_NUM to true in the generated autobuild.h, AND make the file attribute for your project's .rc file to read-write.

    #ifndef __AUTOBUILD_H__
    #define __AUTOBUILD_H__
    //change the FALSE to TRUE for autoincrement of build number
    #define INCREMENT_BUILD_NUM TRUE
    #define BUILD_NUM 2723
    #endif //__AUTOBUILD_H__

    If the flag is true, the project's version number stored in the .rc file is incremented. If the flat is false, or the .rc file is read-only, the version number is not incremented. That is the extent of the change brought about by including the add-in in the project.

    In my project, I also use Manuel Laflamme's code from the CodeGuru.com site, to get the version number from the .rc file and display it in the help-about dialog box. Here is the code snippet that is used to get the version number within the code.

    dlgAbout.cFileVersion.Open(m_sExePath + m_sExeName);
    dlgAbout.m_sBuild = "Pro-JCL version: " +
    dlgAbout.cFileVersion.GetProductVersion();

    In the about box, I have a cstatic control that displays the version number.

    This approach has been a real convenience in my interactions with the QA group. Hope you find it useful.


    Update: 09 Mar 2000.

  • Download updated demo project - 61 Kb

    MSDN recently provided a mechanism for incrementing the version number after each build. The key thing was that they slipped the version resource into the .rc2 file instead of the .rc file. I modified my addin to do the the same. i.e., follow their instructions for moving and modifying the version resource from the .rc to the .rc2 file. Then, add the add-in to your ide as before.

    The file AutoBuild.h will be generated by the developer studio add-in and will contain the following:

    #ifndef __AUTOBUILD_H__
    #define __AUTOBUILD_H__
    //change the FALSE to TRUE for autoincrement of build number
    #define INCREMENT_VERSION FALSE
    #define FILEVER        1,0,0,1
    #define PRODUCTVER     1,0,0,1
    #define STRFILEVER     "1, 0, 0, 1\0"
    #define STRPRODUCTVER  "1, 0, 0, 1\0"
    
    #endif //__AUTOBUILD_H__

    Include the generated file in your project and set the INCREMENT_VERSION flag to TRUE if you want to increment the version number with each build. The version will be incremented with each build. i.e., 1,0,0,1 will become 1,0,0,2 ... 1,0,0,3 ...

    By using FILEVER, PRODUCTVER, STRFILEVER, STRPRODUCTVER strings in place of the version numbers inside the version resource as the MSDN article demonstrates, we get rid of the irritating warning message from developer studio that its reloading the modified .rc file. That message motivated me to modify the code to use their approach.

    Given below is the MSDN / VCDJ documentation for moving the version resource from the .rc file to the .rc2 file and making the appropriate changes to the version number strings.

    Remove the version resource from the .rc file and place it in the .rc2 file:

    Open both MyProject.rc and MyProject.rc2 (found in the Res folder), in a text editor. To use the Visual C++ editor, click Open on the File menu and select Text in the Open As list for the MyProject.rc file.

    Find the version resource statements in MyProject.rc. It should look something like:

    ///////////////////////////////////////////////////////////////////////
    //
    // Version
    //
    
    VS_VERSION_INFO VERSIONINFO
     FILEVERSION 1,0,0,1
     PRODUCTVERSION 1,0,0,1
     FILEFLAGSMASK 0x3fL
    #ifdef _DEBUG
     FILEFLAGS 0x1L
    #else
     FILEFLAGS 0x0L
    #endif
     FILEOS 0x4L
     FILETYPE 0x1L
     FILESUBTYPE 0x0L
    BEGIN
        BLOCK "StringFileInfo"
        BEGIN
            BLOCK "040904b0"
            BEGIN
                VALUE "Comments", "Sample Application\0"
                VALUE "CompanyName", "Microsoft Corp.\0"
                VALUE "FileDescription", "MyProject MFC Application\0"
                VALUE "FileVersion", "1, 0, 0, 1\0"
                VALUE "InternalName", "MyProject\0"
                VALUE "LegalCopyright", "Copyright (C) 1999\0"
                VALUE "OriginalFilename", "MyProject.EXE\0"
                VALUE "ProductName", "MyProject Application\0"
                VALUE "ProductVersion", "1, 0, 0, 1\0"
           END
        END
        BLOCK "VarFileInfo"
        BEGIN
            VALUE "Translation", 0x409, 1200
        END
    END

    Cut the version resource from the MyProject.rc file and paste it into the MyProject.rc2 file below the comment "Add manually edited resources here." For information about what each one of the fields in the resource means, see the VERSIONINFO resource statement in Help.

    Replace the FILEVERSION and PRODUCTVERSION data with macros FILEVER and PRODUCTVER. Similarly, replace the FileVersion and ProductVersion string data with the macros STRFILEVER and STRPRODUCTVER.

    Add a #include AutoBuild.h immediately before the VS_VERSION_INFO resource statement. Now the version resource will look like:

    ///////////////////////////////////////////////////////////////////////
    //
    // Version
    //
    #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 "Comments", "Sample Application\0"
                VALUE "CompanyName", "Microsoft Corp.\0"
                VALUE "FileDescription", "MyProject MFC Application\0"
                VALUE "FileVersion", STRFILEVER
                VALUE "InternalName", "MyProject\0"
                VALUE "LegalCopyright", "Copyright (C) 1997\0"
                VALUE "OriginalFilename", "MyProject.EXE\0"
                VALUE "ProductName", "MyProject Application\0"
                VALUE "ProductVersion", STRPRODUCTVER
            END
        END
        BLOCK "VarFileInfo"
        BEGIN
            VALUE "Translation", 0x409, 1200
        END
    END

    The file AutoBuild.h will be generated by the developer studio add-in and will contain the following:

    #ifndef __AUTOBUILD_H__
    #define __AUTOBUILD_H__
    //change the FALSE to TRUE for autoincrement of build number
    #define INCREMENT_VERSION FALSE
    #define FILEVER        1,0,0,1
    #define PRODUCTVER     1,0,0,1
    #define STRFILEVER     "1, 0, 0, 1\0"
    #define STRPRODUCTVER  "1, 0, 0, 1\0"
    
    #endif //__AUTOBUILD_H__
  • License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    Written By
    United States United States
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    GeneralMy vote of 4 Pin
    haisan5-Feb-11 4:07
    haisan5-Feb-11 4:07 
    GeneralLNK1136 Pin
    miqel31-Oct-07 3:45
    miqel31-Oct-07 3:45 
    Generalauto increase number Pin
    ling_luv28-Jun-07 15:30
    ling_luv28-Jun-07 15:30 
    hi, i have a table in access database call "MovieID" the value is"MV0001" n so on. When i add new record i need the "MovieID" table to be automatically increase the next value to "MV0002" n so on. please advice. thanks.
    GeneralXAutobuild for VS2005 Pin
    Hans Dietrich8-Jun-07 14:04
    mentorHans Dietrich8-Jun-07 14:04 
    GeneralQuestions from a newbie Pin
    Stick^24-May-07 0:12
    Stick^24-May-07 0:12 
    GeneralGreat [modified] Pin
    Waldermort14-Aug-06 18:09
    Waldermort14-Aug-06 18:09 
    GeneralRe: Great Pin
    Stick^24-May-07 0:00
    Stick^24-May-07 0:00 
    GeneralStupid question.. Pin
    benjymous31-Jan-06 23:53
    benjymous31-Jan-06 23:53 
    GeneralRe: Stupid question.. Pin
    HellesAngel18-Jul-06 22:08
    HellesAngel18-Jul-06 22:08 
    Generalresource Pin
    stevev67-Feb-05 6:50
    stevev67-Feb-05 6:50 
    GeneralRe: resource Pin
    Stick^23-May-07 23:53
    Stick^23-May-07 23:53 
    GeneralRe: resource Pin
    stevev625-May-07 2:07
    stevev625-May-07 2:07 
    QuestionRe: resource Pin
    Stick^25-May-07 2:17
    Stick^25-May-07 2:17 
    AnswerRe: resource Pin
    stevev625-May-07 2:48
    stevev625-May-07 2:48 
    GeneralUSEFUL! Pin
    SamKu4-Feb-05 22:37
    SamKu4-Feb-05 22:37 
    GeneralPerfect, just a minor add-on (increase only in release mode) Pin
    gizmocuz19-Aug-04 0:13
    gizmocuz19-Aug-04 0:13 
    GeneralRe: Perfect, just a minor add-on (increase only in release mode) Pin
    rm23-Mar-05 0:27
    rm23-Mar-05 0:27 
    GeneralTrouble building Pin
    SamHackett29-Apr-04 4:06
    SamHackett29-Apr-04 4:06 
    GeneralGOOD But Pin
    11-Jun-02 22:13
    suss11-Jun-02 22:13 
    GeneralA handy addition to this Pin
    Wolfram Steinke10-Jun-01 22:41
    Wolfram Steinke10-Jun-01 22:41 
    GeneralMaking this work with 'Old' projects Pin
    Wolfram Steinke9-Jun-01 15:50
    Wolfram Steinke9-Jun-01 15:50 
    GeneralIncrementing the build number Pin
    Eugen Paval15-Mar-00 3:37
    sussEugen Paval15-Mar-00 3:37 
    GeneralRe: Incrementing the build number Pin
    Syver Enstad30-Apr-00 13:40
    Syver Enstad30-Apr-00 13:40 
    GeneralRe: Incrementing the build number Pin
    amadeolr26-Jan-05 9:36
    amadeolr26-Jan-05 9:36 
    GeneralRe: Incrementing the build number Pin
    fly_horse10-Mar-06 18:41
    fly_horse10-Mar-06 18:41 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.