views:

1467

answers:

8

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?

+3  A: 

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

Lou Franco
Which field of the version number?
Chris Charabaruk
Nice idea, but will probably blow up after changeset-id reaches 0xfffe if you only confine it to one of the version fields, major, minor, build, revision
GertGregers
+2  A: 

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

Bob Dizzle
+1  A: 

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.

Lars Truijens
The recompiling or policy file is only needed if the assembly in Strong Named.
James Curran
Thanks for pointing that out. It is in our case.
Lars Truijens
+3  A: 

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.

James Curran
+2  A: 

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).

korchev
Sounds good, but if you're making multiple builds per day, or maintaining multiple branches, I can see that falling apart pretty quickly.
Chris Charabaruk
Absolutely right. Embedding a build number or the time of build may be a viable workaround.
korchev
You can use the time as well, see http://stackoverflow.com/questions/971476/how-do-i-find-the-current-time-and-date-at-compilation-time-in-net-c-applicatio/971663#971663
Cheeso
+5  A: 

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.

Craig Trader
With CruiseControl.NET you have each and every separate build ever made, there is no reason to rebuild an old version. If you want to add patches to an older version, then you have to branch your code in source control at that specific version.
Sandor Davidhazi
There's a difference between pulling a build from storage, and being able to prove that you've captured all of the pieces necessary to build any given release. There are lots of environmental variables that can affect the creation of any given build. My standard is for a checkout to be as self-contained as possible, such that you can do a checkout on a fresh machine and build the software from scratch. This is harder to achieve with .Net (as opposed to Java) but is still a worthy goal. That means that I've gone so far as to check-in Java, Ant, and all libraries along with my source code.
Craig Trader
+3  A: 

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.

Daniel Fortunov
+6  A: 

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.

Wim Coenen
Yep - much better to use AssemblyInformationalVersion instead.
Wim Hollebrandse
Link to said attribute: http://msdn.microsoft.com/en-us/library/system.reflection.assemblyinformationalversionattribute.aspx
Chris Charabaruk