It’s a good idea for all the assemblies in a single solution to have the same version number, but the default in Visual Studio is for each project to have it’s own AssemblyInfo.cs file, each with it’s own version number. However it’s easy to share a single Version.cs file between all the projects.
First create the Version.cs file as a solution item (right click on the solution, Add, New Item). It should look something like this:
using System.Reflection; [assembly: AssemblyVersion("2.0.1.442")] [assembly: AssemblyFileVersion("2.0.1.442")]
Now remove those same lines (AssemblyVersion and AssemblyFileVersion) from the AssemblyInfo.cs file in each project in the solution.
The next step to add a link to the Version.cs file to each project. Right click on the project and choose ‘Add New Item’ and then ‘Existing Item’. Browse to the Version.cs file in the solution root directory and add it as a link (click on the little drop down arrow on the ‘Add’ button in the file dialogue):
Do this to all your projects. Now you only have to maintain the version number for the whole solution in one place. Nice!
It’s common practice to integrate version numbering with continuous integration. This usually works by having the CI build process update the version number with the build number before each build. Having the number represented in one place makes that much easier.
One last thing you should always do is provide a way for anyone to discover the version number of a running instance of your application. With an ASP.NET MVC web application, it’s a simple as this little controller action:
public ActionResult Version() { var version = Assembly.GetExecutingAssembly().GetName().Version; var versionMessage = string.Format("Suteki Shop. Version {0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.MinorRevision); return Content(versionMessage); }
Now if ever I need to know the version of a running instance I can just type the …/Version URL:
This does seem to be the best way in VS.Net. For some reason our developers often mix C++ or VB.net and C# in the same solution requiring up to 3 files. If you have a deployment project it also needs updating with a separate file.
ReplyDeleteFYI: I blogged on a closely related subject a few months back.
ReplyDeletehttp://alandean.blogspot.com/2010/06/consistent-assembly-versioning.html
Hi Michael, Yeah, I didn't consider the multi-language solution story here. I guess there's no option but to have multiple version files.
ReplyDeleteHi Alan, Thanks for that. A very nice demonstration of how to integrate build number versioning into the build process.
Hi Mike
ReplyDeleteYou can make it even more simpler.
Remove AssemblyFileVersion
If not given, the AssemblyVersion is used.
.peter.gfader.
http://blog.gfader.com
Hi Peter, Great suggestion, thanks for that.
ReplyDeleteHi Mike... MadManWriting here (aka Robin Harris). Like the Blog - good to see you're still banging out the code... Hope all is well with you and yours.
ReplyDeleteHi Robin, Great to hear from you, please drop me a line: mikehadlow at yahoo dot com.
ReplyDeleteVery, very helpful! Thank you.
ReplyDeleteYou can do search and replace across the AssemblyInfo files in your solution using this regular expression to remove the entries that you're replacing with the common version.cs
ReplyDelete^\[assembly\: Assembly(Company|Product|Copyright|Version|FileVersion)\(".*"\)\]$
Hi,
ReplyDeleteGreat post I am very keen on standardising version numbers across a project when creating major releases so this is very helpful.
It's nice because you can modify the "Assembly Information" properties within Visual Studio and the version numbers are just left blank. If a developer mistakenly enters a version number it fails to build with a duplicate version error.
Very nice.
Thanks,
Dave
http://centrel-solutions.com
I have a website project and added a assemblyinfo.cs file to the appcode. When i deployed the files, the page level dlls were all 0.0.0.0
ReplyDeleteThanks for posting this, it's exactly what I was looking for.
ReplyDelete