Click here to Skip to main content
Click here to Skip to main content
Go to top

Automated Versioning of Your Visual Studio Build

, 27 Aug 2010
Rate this:
Please Sign up or sign in to vote.
Helps you to use your resource file to build automated versioning controller

Introduction

Here, I'm going to explain a simple mechanism which will help you to add version information for the build done in Visual Studio. The main advantage of this approach is it provides the flexibility of controlling the version update format by simply modifying the source provided by this article.

Once you modify the provided code and configure it accordingly, it will do the version update automatically.

Background

I have gone through a few articles and decide to implement something very simple that will automate version number management. As a result, I have used a simple header with #define directive that contains version data. This header is created by our simple application and updates the last digit and writes back new version data to the same header.

This version data header is accessed by resource file(.rc) at the post build event and used for version generation.

Using the Code

  1. Add a header file named VersionNo.h into directory represented by $(InputDir) macro.

    InputDir.jpg

    File should contains the following two entries:

    #define FILEVER        2,0,0,5
    #define PRODUCTVER     2,0,0,0 		 
  2. Create a resource file in your Visual Studio project at the directory represented by $(InputDir) and add the following script to the file if it doesn't exist or modify it to be like that.
    #include "VersionNo.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 Application\0"
                VALUE "FileVersion", FILEVER  
                VALUE "InternalName", "MyProject\0"
                VALUE "LegalCopyright", "Copyright (C) 2010\0"
                VALUE "OriginalFilename", "MyProject.EXE\0"
                VALUE "ProductName", "MyProject Application\0"
                VALUE "ProductVersion", PRODUCTVER
            END
        END
        BLOCK "VarFileInfo"
        BEGIN
            VALUE "Translation", 0x409, 1200
        END
    END
  3. Now compile your myExe project and copy the output (.exe) to the same directory as above.
  4. Finally, right click your project and goto Build Events -> Post-Build Event and in Command Line input box, add the following line.
    "$(InputDir)"\myExe.exe	

    Now compile your project and right click on your output and go to Details tab to see the result.

    final.jpg

Points of Interest

MyExe project is a simple project that reads a given file and rewrites the same thing back with some modifications (by increasing the last digit of version number). You can extend this to write a suitable version update controller that matches your requirements by having some knowledge in C++.

History

  • 27th August, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

suranjithe
Software Developer
Sri Lanka Sri Lanka
www.simplepap.blogspot.com

Comments and Discussions

 
Generalf*** you .. PinmemberCoolDude28786-Oct-10 10:14 
AnswerRe: f*** you .. Pinmembersuranjithe26-Oct-10 4:51 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 27 Aug 2010
Article Copyright 2010 by suranjithe
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid