[转]Getting svn revision number from NAnt

时间:2021-11-14 18:38:04

本文转自:http://www.cosminonea.net/2009/10/getting-svn-revision-from-nant.html

 

http://*.com/ has got the svn revison number in the footer which is quite cool especially when you have a build script that deploys the application automatically.

This is how you can get the revision from svn: 
svn info --xml [repository url]

which returns 
<?xml version="1.0"?> 
<info> 
  <entry 
     kind="dir" 
     path="." 
     revision="6"> 
    <url>http://svnserver/svn/svnrevisiondemo/trunk</url> 
    <repository> 
      <root>http://myserver/svn/svnrevisiondemo</root> 
      <uuid>cb474c29-17db-0310-ba2e-db2fec5ab780</uuid> 
    </repository> 
    <commit 
       revision="6"> 
      <author>cosmin</author> 
      <date>2009-10-25T17:09:08.315246Z</date> 
    </commit> 
  </entry> 
</info>

The most important bit in this output is the revision attribute of the commit node. This is the NAnt task that peeks into the xml above and extracts the revision number: 
    <target name="find-svnrevision"> 
        <property name="svn.revision" value="0"/> 
        <exec program="svn" 
            commandline='info "${project::get-base-directory()}" --xml' 
            output="svninfo.xml" 
            failonerror="false"/> 
        <xmlpeek 
            file="svninfo.xml" 
            xpath="/info/entry/commit/@revision" 
            property="svn.revision" 
            failonerror="false"/> 
        <echo message="Building revision number: ${svn.revision}"/> 
    <delete file="svninfo.xml" failonerror="false" /> 
  </target>