Click here to Skip to main content
Email Password   helpLost your password?
  • 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__
    
    
  • You must Sign In to use this message board.
     
     
    Per page   
     FirstPrevNext
    GeneralLNK1136
    miqel
    4:45 31 Oct '07  
    I got liner error, some times windows closes linker (becouse of error) Have you got any ides what is wrong?

    .\Release\addinn.res : fatal error LNK1136: invalid or corrupt file
    Error executing link.exe.

    Generalauto increase number
    ling_luv
    16:30 28 Jun '07  
    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
    Hans Dietrich
    15:04 8 Jun '07  
    I have posted an update to Autobuild (not an add-in) that can be used with VS2005; it uses the same Autobuild.h file:
    http://www.codeproject.com/useritems/XAutobuild.asp


    GeneralQuestions from a newbie
    Stick^
    1:12 24 May '07  
    Exactly what I'm looking for, but:

    a) Where do I put the add-in? I tried in the VS add-ins folder, and
    do not see it in the add-on manager.

    b) How could one make this be in the add-in folder to toggle off if desired?

    c) When I wish to publish a Major/Minor Version, where do I change those
    numbers, and how do I "reset" the build to zero?

    Thanks,

    Patrick
    patrick "at" benchmark-avionics.com

    GeneralGreat [modified]
    waldermort
    19:09 14 Aug '06  
    Nice tool, works like a charm. After including the dll a button appeared in VS, but it does not do anything!

    After reading some of the other comments I just want to point out a few things.

    1. Regserv32 is not required, you need to copy the dll to the VS directory and locate it from within VS.

    2. Add a #include "*.rc2" into your *.rc file. e.g.
    #ifdef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    // // TEXTINCLUDE
    // #include "SanZhong.rc2" // include the 1 TEXTINCLUDE DISCARDABLE
    BEGIN
    "resource.h\0" END

    3. Only the dll is required from the zip files. Perhaps the author could create a saller zip containing only the dll???


    -- modified at 0:10 Tuesday 15th August, 2006
    GeneralRe: Great
    Stick^
    1:00 24 May '07  
    So, where do I put the .dll exactly? I'm lost.


    Patrick
    GeneralStupid question..
    benjymous
    0:53 1 Feb '06  
    How do I install the addin dll?

    --
    Help me! I'm turning into a grapefruit!
    Buzzwords!

    GeneralRe: Stupid question..
    HellesAngel
    23:08 18 Jul '06  
    Fishing around in the help files I found that you should "If you are using Visual Basic .NET or Visual C# .NET, enter regasm .dll where is the name of the Add-in. If you are using Visual C++ .NET, use regsvr32.". However it doesn't work for me. An error box pops up saying LoadLibrary couldn't find the module. No idea what to do next.

    This seems far too complicated just to have an auto-incrementing build number.
    Generalresource
    Steve Vreeland
    7:50 7 Feb '05  
    It's a little easier to use the resource directly:


    struct VS_VERSIONINFO
    {
    WORD wLength; // of this structure without the padding
    WORD wValueLength; // byte length of the 'Value' member
    WORD wType; // 1 if text , 0 if binary
    WCHAR szKey[15]; //
    WORD Padding1[2];
    VS_FIXEDFILEINFO Value;
    };

    BOOL CFileVersion::GetResourceInfo(VS_FIXEDFILEINFO& vsffi)
    {
    VS_FIXEDFILEINFO* pVsffi;
    HRSRC hrc = FindResource(NULL,MAKEINTRESOURCE(VS_VERSION_INFO),RT_VERSION);
    if ( hrc != NULL )
    { //Load the resource
    HANDLE hr = LoadResource(NULL, hrc);
    if ( hr != 0 )
    {
    VS_VERSIONINFO* pvi = (VS_VERSIONINFO*)LockResource(hr);
    if ( pvi != NULL )
    {
    pVsffi = &(pvi->Value);
    vsffi = *pVsffi;
    return TRUE; // success
    }

    }
    }
    return FALSE;// error
    }




    stevev
    GeneralRe: resource
    Stick^
    0:53 24 May '07  
    What do you mean exactly? How do you use the above? I am guessing you mean vs. FileVersion, but how would you use what you have posted?


    Patrick

    GeneralRe: resource
    stevev6
    3:07 25 May '07  
    CFileVersion class handles getting the fileVersion or productVersion and formatting it into strings I use to display the info.
    GetResourceInfo() is done during start-up.
    I use fileversion for my debug build number and productversion for my release version number.
    -Thanks for a great example. It has helped keep my stuff straight for the last two years...

    QuestionRe: resource
    Stick^
    3:17 25 May '07  
    You replied to the wrong post, making it look like you were responding to my questions.

    Are you using this with VS2005?


    AnswerRe: resource
    stevev6
    3:48 25 May '07  
    no - vs 6
    GeneralUSEFUL!
    SamGw
    23:37 4 Feb '05  
    nice tool!
    Thank you very much!
    GeneralPerfect, just a minor add-on (increase only in release mode)
    gizmocuz
    1:13 19 Aug '04  
    Works like a charm! I personaly dont like the build number be increased when i am building my software (debug mode), so i replaced the line with 'INCREMENT_VERSION' with these lines. Now it only increases in release mode.

    #ifdef _DEBUG
    #define INCREMENT_VERSION FALSE
    #else
    #define INCREMENT_VERSION TRUE
    #endif

    GeneralRe: Perfect, just a minor add-on (increase only in release mode)
    rm2
    1:27 3 Mar '05  
    Does your suggestion really work??? Unsure

    In file command.cpp add (Addition marked bold):

    HRESULT CCommands::XApplicationEvents::BeforeBuildStart()
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    //=====================================================================
    IDispatch* pDispatch;
    m_pCommands->GetApplicationObject()->get_ActiveProject(&pDispatch);
    if (!pDispatch)
    {
    m_pCommands->GetApplicationObject()->PrintToOutputWindow(CComBSTR(_T("Build Number Unchanged")));
    return S_OK; // or some error message
    }
    CComQIPtr pProject(pDispatch);
    CComBSTR bsName;
    pProject->get_FullName(&bsName);
    CString sName = bsName;
    pDispatch->Release();
    //======================================================================
    m_pCommands->GetApplicationObject()->get_ActiveConfiguration(&pDispatch);
    if(!pDispatch)
    {
    m_pCommands->GetApplicationObject()->PrintToOutputWindow(CComBSTR(_T("Build Number Unchanged")));
    return S_OK; // or some error message
    }
    CComQIPtr pConfiguration(pDispatch);

    CComBSTR bsConfigName;
    pConfiguration->get_Name(&bsConfigName);

    pDispatch->Release();

    CString sConfigName = bsConfigName;
    sConfigName.MakeUpper();
    if(sConfigName.Find(_T("DEBUG")) != -1)
    {
    m_pCommands->GetApplicationObject()->PrintToOutputWindow(CComBSTR(_T("Build Number Unchanged")));
    return S_OK; // or some error message
    }
    //======================================================================
    m_pCommands->GetApplicationObject()->PrintToOutputWindow(bsName);

    // check whether the application file has a incrementbuild flag set.
    int iLastSlash = sName.ReverseFind('\\');
    if(iLastSlash == -1)

    GeneralTrouble building
    SamHackett
    5:06 29 Apr '04  
    Hello,

    I would really love to use this, but I can't get the download to load in VS, two of the projects are reported as corrupted.

    Could anybody just send me a copy of the dll please, so I don't have to build the project?

    If so, I would really appreciate getting hold of it as soon as possible, as it is for work, where I am right now. Smile
    GeneralGOOD But
    agent_008
    23:13 11 Jun '02  
    I realy like your project. But a lot of handy work -- cut, change .. many work
    Possible aoutomation?Confused
    GeneralA handy addition to this
    Wolfram Steinke
    23:41 10 Jun '01  
    It would be handy if the location of the autobuild header file could be configurable and stored in the workspace file.

    The project I was having problems with to make this work - consists of a workspace with over 30 project files, and only one autobuild header for the lot in a common include directory. This could however be moved and reference in another way.

    Happy programming!!
    GeneralMaking this work with 'Old' projects
    Wolfram Steinke
    16:50 9 Jun '01  
    Thanks for a good add-in.

    However I am having trouble making it work with and older group of projects.
    Firtly it only needs to work with one element in the overall group.
    However the header file is not generated automatically and if I place it there it is not incremented.

    Is there a trick I have missed when adding this to an existing project. It works beautifully in new ones.

    Happy programming!!
    GeneralIncrementing the build number
    Eugen Paval
    4:37 15 Mar '00  
    Unfortunately this works only for MFC. In ATL there is no RC2 file and if you modify the RC file to include an arbitrary created RC2 file this will get overwritten the next time you make a modification to the RC file.

    Another problem is that some of us are using VSS or other version control systems. So, it is likely the RC file is read-only most of the time since you have to check-out the file prior to any modification. I have yet to find a way to do that programmatically
    GeneralRe: Incrementing the build number
    Syver Enstad
    14:40 30 Apr '00  
    You can include an .rc2 file by modifying the TEXTINCLUDE resource statement in the .rc file to #include the rc2 file. This will insure that the include is not overwritten.

    As to the problem of the RC file being read-only, I can only say that the .rc file is not modified, only the header needs to be modified
    GeneralRe: Incrementing the build number
    amadeolr
    10:36 26 Jan '05  
    I want to add version and build information to a Win32 application. The example code above creates a DLL. How do I use this DLL in a Win32 application?

    Thanks
    GeneralRe: Incrementing the build number
    fly_horse
    19:41 10 Mar '06  
    Can I add version and build information to a console application.

    Thanks.


    Last Updated 9 Mar 2000 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010