Click here to Skip to main content
15,749,352 members
Articles / Programming Languages / Visual Basic
Posted 6 Apr 2007


61 bookmarked

How to Keep Your Sanity and Multiple Projects Version Numbers in Sync

Rate me:
Please Sign up or sign in to vote.
4.92/5 (26 votes)
23 Apr 2007CPOL2 min read
A simple solution to keeping multiple projects version numbers in sync

Introduction: Versioning Troubles

In the project I'm currently working on, we have multiple projects in one solution. One of the problems we've faced is how to keep all the version numbers (generally found in the ApplicationInfo file) in sync. Ok, so "problem" might be too strong of a word. It's more of an annoyance, but nonetheless, it would be nice to have some sort of automated solution. The other day, I downloaded some sample code for an unrelated issue, but they had a really nice solution to the versioning puzzle. I've now added this solution to my current project, with a few little wrinkles, and it seems to be working really well (we won't know for sure until the next release). [NOTE: this solution assumes you want the same version number for each project in the solution]

The Short of It

Here's what you need to do:

  1. Remove these attributes from the AssemblyInfo files in each project in the solution:
    [assembly: AssemblyVersion("")]
    [assembly: AssemblyFileVersion("")]
  2. Create a new file in the root directory of the solution (I named mine VersionInfo).
  3. Add the attributes that we removed from the AssemblyInfo file to your new file (you'll also need to add a reference to the System.Reflection namespace).
  4. On each project in the solution, right click the project and select Add->Existing Item.
  5. HERE'S THE KEY. Browse to your newly created version file, but instead of clicking the "Add" button, click the little down arrow next to the word "Add" and then click "Add as link" from the menu it drops down.

What Did We Just Do?

Normally when you add an existing file, the IDE copies the selected file to the current directory. By selecting "Add as link," what we've done is link the file in from its original location (yes, I know you figured that out from the name "Add as link"). Now when we build our solution, each project will compile in the exact same file (VersionInfo in my case) , thus giving each project the same version number.

The Next Step

To make this really cool (well, at least I think it's cool) I've created a build script to automate the process of creating the release build. The script prompts for the version number of the release and updates the version file before doing the build. Here's a snippet of my script (parts of this script were omitted to protect the innocent)...

Dim versionNumber 
Set shell = CreateObject("WScript.Shell") 
Set fileSystemObject = CreateObject("Scripting.FileSystemObject") 

sub Main() 
    Echo "Getting version number" 
    versionNumber = InputBox("What version is this build?", "Version") 
    UpdateFileVersion versionNumber 


    Echo "Building" 
    RunCommand _
        """C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe""_
        SolutionName.sln /Rebuild Release", "Failed to build" 


end sub 

sub Echo(message) 
    WScript.Echo message 
end sub 

sub UpdateFileVersion(versionNumber) 
    Set file = fileSystemObject.OpenTextFile("Version.cs", 2) 

    file.WriteLine "using System.Reflection"+ vbcrlf + _ 
        vbcrlf + _ "[assembly:AssemblyVersion""" + _
        versionNumber + ".0.0"")]" + _
        vbcrlf + "[assembly:AssemblyFileVersion""" + _
        versionNumber + ".0.0"")]" 

end sub 

sub RunCommand(command, failMessage) 
    result = shell.Run(command, 1 , 1) 
    TestResult result, failMessage 
end sub 

sub TestResult(result, failMessage) 
    if result <> 0 then 
    end if 
end sub 



I now have a very simple and very automated versioning process. It makes sure that our projects' version numbers are never out of sync and, more importantly, makes sure that I don't forget to update the version numbers when I do a final release build. I hope this helps.


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

Written By
Software Developer (Senior) Scratch Audio
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

Praise.NET Core versioning Pin
RickZeeland24-Feb-18 10:28
mveRickZeeland24-Feb-18 10:28 
GeneralCompile Pin
gotorg22-Apr-08 9:37
gotorg22-Apr-08 9:37 
GeneralThanks Pin
Anthony Bouch15-Apr-07 13:50
Anthony Bouch15-Apr-07 13:50 
QuestionMSBuild? Pin
Chris Richner13-Apr-07 16:45
Chris Richner13-Apr-07 16:45 
AnswerRe: MSBuild? Pin
Herbrandson17-Apr-07 5:57
Herbrandson17-Apr-07 5:57 
GeneralRe: MSBuild? Pin
Chris Richner17-Apr-07 7:41
Chris Richner17-Apr-07 7:41 
GeneralRe: MSBuild? Pin
Shaun Wilde16-May-07 13:00
Shaun Wilde16-May-07 13:00 
Generalif only i had known this... Pin
jburrow11-Apr-07 3:15
jburrow11-Apr-07 3:15 
QuestionGreat! Where is the rest of it? Pin
flipdoubt7-Apr-07 4:50
flipdoubt7-Apr-07 4:50 
AnswerRe: Great! Where is the rest of it? Pin
dabs9-Apr-07 4:24
dabs9-Apr-07 4:24 
AnswerRe: Great! Where is the rest of it? Pin
Herbrandson9-Apr-07 5:08
Herbrandson9-Apr-07 5:08 
GeneralCool Pin
Josh Smith6-Apr-07 18:12
Josh Smith6-Apr-07 18:12 

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.