Germán Schuager's blog

NAnt task for getting Mercurial current revision

As part of my continuous integration process I like to get the current VCS revision and stick it somewhere in the build output (almost always to be displayed in some kind of "About" screen)

When using Mercurial in combination with NAnt, you can do this as follows:

<property name="hg.revision.hash" value="N/A" />

<target name="common.find-hginfo">
   <property name="vcs.revision" value="0" overwrite="false" />
       commandline='parents --template="{node|short}"'
   <loadfile file="_revision.txt"
             property="hg.revision.hash" />
   <property name="hg.revision.hash" value="${string::trim(hg.revision.hash)}" />
   <delete file="_revision.txt" failonerror="false" />
   <echo message="INFO: Using Hg revision: ${hg.revision.hash}"/>

Just put this target as a dependency somewhere else and use the property "hg.revision.hash" as you see fit.