all posts

More fun with CruiseControl.NET, NAnt and Subversion Another method for getting the Subversion Revision Number in NAnt

Published to Blog on 6 Apr 2006

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:

K 25
V 21

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:

    ... run the tortoise command line stuff ...                ... run svn-update NAntContrib task ...      ... run the svn command line log and xmlpeek that Jonathan provided and assign that to property svnrevision ...     The NAnt loadfile task loads the contents of a file into a supplied property.  I then use the regex task to pull out the reversion number from those contents and assign it to another property.  Now I have my svn revision number and I can add it into my version number logic.  YMMV - this logic has been tested on two computers only: our build server and my laptop, which has the same setup as the build server except that the build server has a newer version of Subversion that uses .svn directories and my laptop has the older version that uses the _svn folder hack.  The above example works in both cases.

Technorati Tags: NAnt, CruiseControl.NET, Subversion

Dan Hounshell
Web geek, nerd, amateur maker. Likes: apis, node, motorcycles, sports, chickens, watches, food, Nashville, Savannah, Cincinnati and family.
Dan Hounshell on Twitter

  • On 6 Jul 2007 "billie"" said:
    good tips, helped me get subversion with set up. Was having trouble getting my versioning just right.
  • On 6 Jul 2007 """ said:
    Billie, I'm glad it helped!