I like to have meaningful version numbers in my .NET assemblies. I don't understand people who put an incremental build number in the version. Ok, you know it's build 28 but what does it mean besides that it was build before build 29.
I usually put 2 pieces of valuable information in the Assembly version: the date on which the build was done and the revision from Subversion. Agreed, we can find out the date from the revision but you can parse the date and put it in the about box of the application.
For example, version 1.1.70312.256 means the build was done on March 12 2007 and it comes from revision 256 in Subversion. You can also put the day of the year instead of a formatted date. For example, build 1.0.59.256 would mean the build was done at the end of February as the 59th day of the year is close to that.
Anyway, when you are building your application with NAnt, it's pretty straightforward to grab the current date and make a number out of it. Use the <script> task and you're done.
But finding the revision number is a little bit harder. I tried the Subversion tasks with NAntContrib but they were buggy. So I ran a Subversion command line program with the <exec> task to get my revision number. I then parsed the output of this command to find the revision number. The NAnt script looks something like this:
<target
name="getHeadRevision">
<exec
program="svn.exe"
basedir="C:\Progra~1\Subversion\bin" commandline="info URL
--username XXX --password XXX"
output="${svn.info.log}"
resultproperty="svn.head.revision"
/>
<!-- Load the content of the file in property
svn.head.revision -->
<loadfile
property="svn.head.revision" file="${svn.info.log}" />
<!-- Look
for the 'vision: ' string -->
<property
name="index.of.revision" value="${string::index-of(svn.head.revision,
'vision: ')}" />
<!-- Make
sure we have found the index of the substring -->
<if
test="${bool::parse(int::parse(index.of.revision) != -1)}">
<property
name="svn.head.revision"
value="${string::substring(svn.head.revision,
int::parse(index.of.revision) + 9, 3)}"
verbose="true"/>
<delete
file="${svn.info.log}" />
<echo
message="Rev: ${svn.head.revision}"/>
</if>
</target>
One last thing is to try your script inside of CruiseControl. I work in a French environment and this has lead me to a silly situation. When I run this script inside of CruiseControl, which is running from the command prompt, svn.exe returns a string in English. But if I run CruiseControl as a service, svn.exe returns the string in French, which means I can't look for the same string.