![]() |
Languages »
C# »
How To
Beginner
License: The Code Project Open License (CPOL)
How to Keep Your Sanity and Multiple Projects Version Numbers in SyncBy HerbrandsonA simple solution to keeping multiple projects version numbers in sync |
C#, VB 7.x, VB 8.0, VB 9.0, Windows, .NET 1.0, .NET 1.1, .NET 2.0, .NET 3.0VS.NET2003, VS2005, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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]
Here's what you need to do:
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] System.Reflection namespace). 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.
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
CommitToVersionControl
GetLatestFromVersionControl
Echo "Building"
RunCommand _
"""C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe""_
SolutionName.sln /Rebuild Release", "Failed to build"
RunUnitTests
CreateZipFile
MsgBox("Done.")
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"")]"
file.Close
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
MsgBox(failMessage)
WScript.Quit
end if
end sub
Main
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.
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 23 Apr 2007 Editor: Genevieve Sovereign |
Copyright 2007 by Herbrandson Everything else Copyright © CodeProject, 1999-2009 Web15 | Advertise on the Code Project |