Subversion Revision Number in NAnt

Presenting the holy grail of NAnt and Subversion driven build scripts, this target gets the current subversion revision number from the directory in the “src.dir” property:

<target name="getSubversionRevision">
    <!-- Retrieve subversion revision number -->
    <echo message="Retrieving Subversion revision number"/>
    <property name="svn.revision" value="0"/>
    <exec
        program="svn"
        commandline='log "${src.dir}" --xml --limit 1'
        output="${src.dir}\_revision.xml"
        failonerror="false"/>
    <xmlpeek
        file="${src.dir}\_revision.xml"
        xpath="/log/logentry/@revision"
        property="svn.revision"
        failonerror="false"/>
    <echo message="Using Subversion revision number: ${svn.revision}"/>
</target>

Shamelessly stolen from Jonathan Malek.