April 06, 2006

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

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
svn:wc:ra_dav:version-url
V 21
/YourProjectName/!svn/ver/99/
END

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:

<property name="svnrevision" value="0"/>
<property name="svnrevisiontortoise" value="nothing" />
<if test="${directory::exists('_svn')}">
    ... run the tortoise command line stuff ...
     <loadfile file="${checkoutdirectory}\_svn\dir-wcprops" property="svnrevisiontortoise" failonerror="false" />
     <regex pattern="ver\/(?'svnrevision'\w+)\/" input="${svnrevisiontortoise}" failonerror="false" />
</if>
<if test="${directory::exists('.svn')}">
     ... run svn-update NAntContrib task ...
     ... run the svn command line log and xmlpeek that Jonathan provided and assign that to property svnrevision ...
</if>
<echo message="Using Subversion revision number: ${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: , ,

Comments,

  • Trackbacks,
  • and Pingbacks
  1.  avatar billie says:

    good tips, helped me get subversion with cc.net set up.  Was having trouble getting my versioning just right.

  2.  avatar says:

    Billie, I'm glad it helped!

Comments are closed.

Shortcuts

Where is Dan?


My Blog
My Blog
Twitter
Twitter
Facebook
Facebook
LinkedIn
LinkedIn
Flickr
Flickr
YouTube
YouTube
Delicious
Delicious
Foursquare
Foursquare
Pinterest
Pinterest
GetGlue
GetGlue
Pintley
Pintley
XBOX Live
XBOX Live
Last.fm
Last.fm
Windows Live
Windows Live
Telligent.com
Telligent
Graffiti CMS on CodePlex
Graffiti CMS
Popular

Recent Posts