Thursday, March 19, 2009

Fixing a NullReferenceException with NAnt 0.86-beta1 and .Net 3.5

My attempts at building a .Net 3.5 application with NAnt 0.86-beta1 resulted in a NullReferenceException before it ran any targets. Debugging NAnt revealed the error. The NAnt.exe.config file in my NAnt installation had this readregistry task in the framework element for the "net-3.5" framework, near line 470:

    key="SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A\WinSDKNetFxTools\InstallationFolder"
    failonerror="false" />

The error is the key attribute, which I changed to:

SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.1\WinSDKNetFxTools\InstallationFolder

because I had installed the .Net 3.5 SDK after the release of .Net 3.5 SP1.

Sunday, March 15, 2009


Having set up a nice build process using NAnt, I didn't expect to have to pick up another build tool. However, in my endeavor to create a development environment without Visual Studio, I've run into stumbling block to creating WPF applications. It seems that Microsoft distributes no XAML compiler with the .Net Framework. Instead, they built that ability into MSBuild. So much for simplicity.

Saturday, March 14, 2009

NAnt: Getting Subversion Revision

I'm sure this may be old news for many of you, but it isn't for me. This NAnt include file extracts the revision number for the HEAD revision for the base project directory (the directory of the build file that was invoked) into a property called "svn.revision":

    <property name="svn.revision" value="0" />
    <target name="svn-revision">
            commandline="info ${project::get-base-directory()}@HEAD --xml"
            failonerror="false" />
            failonerror="false" />
        <delete file="_svnrev.xml" />
        <echo message="SVN Revision: ${svn.revision}" />

This script requires a Subversion client. Being a TortoiseSVN fan, I looked into its automation potential. Unfortunately, it wouldn't do anything without popping up window of some sort, and I sought a quieter approach. Hence, the command-line Subversion client.

The exec task invokes the SVN "info" subcommand, passing the option to output the results as XML. Then, it stores the XML in a temporary file. Finally, the xmlpeek task uses XPath to read the revision number from the temporary file.