13
votes

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?

8

8 Answers

9
votes

I see many posts here about using the subversion revision number as a component of the assembly version. Beware: the 4 version numbers available in windows (a.b.c.d) are each limited to 16 bit (max = 65535). The subversion revision number can easily exceed this limit, especially if you host multiple projects in the same repository.

5
votes

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.

4
votes

At a previous job, where we used Subversion, I had a nant script run about ccnet to extract the repository version and used that as the final number.

At this job, we use VSS (shutter), so that's not really an option, so we have a policy of updating it manually, with the following guidelines:

  • Major : significant ( > 25%) changes or addition in functionality or interface.
  • Minor : small changes or additions in functionality or interface.
  • Build : minor changes that break the interface.
  • Revision: fixes to a build which do not change the interface.

We also keep the Assembly & the File versions in sync. The Assembly version can be easily read programmatically, while the file version can be displayed as a column in Details mode in Windows Explorer.

3
votes

Our build scripts inject the changeset number from TFS into the version. That way we know exactly what checkins are in the build.

3
votes

We have our CruiseControl.NET build server embed the perforce changelist number into the AssemblyFileVersion — this lets us track back to the source code for any assembly built by the build server. (We always build from the main branch.)

For assemblies that customers will be referencing we leave the AssemblyVersion constant unless there are breaking changes, in which case we increment the version to ensure that customer code gets re-built against the new version.

2
votes

We use the versioning from subversion and have the buildscripts update the assembly version info, so source checkins control versioning.

2
votes

We tend to embed the release (or build) date into the assembly. For example if built today the version would be "2008.10.06" (the build script updates it).

1
votes

The AssemblyVersionAttribute is part of an assembly's identity. Changing that means it is a different assembly and programs linking to that assembly need to be recompiled/linked or a version policy need to be applied. We didn't find that apealing so we choose to only increase the AssemblyFileVersion for each hotfix and only change the AssemblyVersion for each major release. We are aware that this decision brings back some of the win32 dll hell. We increase the AssemblyFileVersion for each build and label/tag the version control system with that version so we know from what source the binary came.