R – the best way to use assembly versioning attributes

assembliesnetversioning

The AssemblyVersion and AssemblyFileVersion attributes are the built-in way of handling version numbers for .NET assemblies. While the framework provides the ability to have the least significant parts of a version number (build and revision, in Microsoft terms) automatically determined, I find the method for this pretty weak, and no doubt have many others.

So I'd like to ask, what ways have been determined to do the best job of having version numbers that better reflect the actual version of a project? Do you have a pre-build script that sets part of the version to the date and time, or repository version for your working copy of a project? Do you just use the automatic generation provided by the framework? Or something else? What's the best way to manage assembly/file versioning?

Best Answer

On my current project, we use the Subversion revision number as the least significant (build) part of the version number, and we use a Nant script to create the project AssemblyInfo file. We use the same version number for both the AssemblyVersion and AssemblyFileVersion attributes. (The other three parts are major.minor.point, where major.minor will be incremented every time there's a database schema change, and point is incremented for each release.)

We started out with the build number being simply incremented, but that required that the version file be checked in for every build, and caused conflicts when merging. When that proved unworkable, we started using CruiseControl.NET to generate the build number, but that made it difficult to reproduce specific builds manually. Eventually we went to the current (Subversion-revision) scheme.

Note: Unfortunately with .NET, it is not possible to perfectly recreate a build from a past revision, because the .NET compilers encode the current timestamp into the object file when compiling. Every time you compile the same code, you get a different object file.