Setting meaningful version numbers for .Net projects

Posted by Adrian Tue, 14 Jul 2009 14:18:00 GMT

This handy little command line tool (C# source included) will hunt through the folders of your solution looking for AssemblyInfo.cs files. If it finds any, it'll prompt you for a new version number and will then update all values of AssemblyVersion and AssemblyFileVersion with the new value. This makes it very easily to ensure that your version numbers are always meaningful.

A great deal of our primary work involves providing frameworks and libraries that other developers use in their projects. One of the most common problems we face is keeping version numbers meaningful. Visual Studio lets you set a version number in the properties of your project (you open properties in the solution explorer and then click Version Information to do this). Unfortunately it's quite long-winded, especially if you solution spans several projects (or worse still, your project has many solutions).

This little command line tool starts in the current directory and scans through all sub-directories, looking AssemblyInfo.cs files (these are where the properties are stored). If it finds any, if asks you for a new version number and then updates all of the AssemblyInfo.cs files with this new value.

Here's a sample use. I will assume that you've downloaded the tool and saved it to somewhere on your default PATH, for simplicity's sake. Here's a sample console output, showing the tool in use from the command line:

C:\Projects\MyFramework> SetAssemblyVersion.exe
Searching... 

Found 39 AssemblyInfo.cs files. Please specify the new version number:
1.1.0.456
Writing C:\Projects\MyFramework\ServerApi\Properties\AssemblyInfo.cs...
Writing etc...
Done

C:\Projects\MyFramework>

We have adopted a company wide convention for our version numbering scheme that makes it very easy to identify a given DLL or executable, and to know exactly what updates are available and when that DLL was compiled. We number our versions like this:

MajorVersion.Phase.Sprint.SourceCodeRevision

This ties in quite well with most modern enterprise development/project management methodologies, and gives us plenty of information in return.

Download it now: SetAssemblyVersion.exe

For those interested in modifying this tool, here is the source: SetAssemblyVersion.cs. The uncompiled source code is released to the public domain, without restriction, but we'd like it if you got in touch to share any enhancements that you make.

A final note: We don't actually set our version numbers by hand for our largest projects - we use customised msbuild files on our continuous integration server. We'll write another article soon to explain how you can automatically set version numbers before a build using Team City, including using the source repositories revision number as one of the version number components, as explained above.


About

We are a small British company that produces business-oriented software and solutions. These articles are a product of our daily work - information that we think might be useful to share. We hope you find them useful.

Our Software

These are some of our products. Several are open source, some are web-based and others are proprietary:

Categories

Archives

Syndicate

ml> ._trackPageview(); } catch(err) {} ml> l> pageTracker._trackPageview(); } catch(err) {} ml> ._trackPageview(); } catch(err) {} ml> l>