Earlier this week I got our build server versioning our builds using the standard x.x.x.x nomenclature where the first two sets are major and minor versions, which are manually set and updated when appropriate, the third number is the build number as supplied by CruiseControl.NET at build time and the fourth digit (the revision number) was just 0. All the AssemblyInfo.cs files in each project are updated with the version info and I now zip up a distributable copy of the code and apply the version number to it as well. Most of the knowledge for the above was learned from Marc Holmes’ Expert .NET Delivery.
As a team we decided that we wanted to add the Subversion revision number into our version number as the final set of digits. I did a search on google and found Jonathan Malek’s CruiseControl.NET and Subversion Revision Numbers using NAnt. This worked great - in some cases.
Our build files make use of another Jonathan Malek example: NAnt, Subversion and VS.NET where if the computer has the version of subversion that uses “_svn” directories it calls the TortoiseSVN command line for the build and if it has the “.svn” directories it calls the svn command line directly. This is a nice hack.
Getting the revision number using Jonathan’s example did not work on computers that had the _svn directories (on the one example that I tried - my laptop) so I had to come up with another way. After some poking around I found that the revision number is stored in the file: \_svn\dir-wcprops, where the contents look like this:
In the above case 99 is the revision number. So now how do I get to it from inside the NAnt build script? At first I thought I was going to have to write a NAnt extension, but then I found the NAnt loadfile task. Now I do this: