Thursday, February 21, 2008

Tools for Authoring NAnt Build Files

NAnt is a great tool for automating many computer tasks. For a quick introduction, check my previous articles Automating Your Computer Tasks with NAnt and Use NAnt and WinRar to Create a Self Extracting Archive. Authoring NAnt build files can be difficult without a good editor and editing XML is not my favorite thing to do anyway. Having to know all the tags and parameters for each NAnt task, makes it even less desirable. Looking at the current options, you can find several tools for authoring NAnt build files:

While the tools above will do the job, it would be nice if you could edit your build files in Visual Studio and have at least the basic intellisense that the IDE provides. It turns out that editing NAnt build files with VS and having code insight is a pretty easy thing to setup. Here is how it is done:

  1. Install the NAnt schema by copying the file "nant.xsd" form the NAnt distribution to "C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas". Update: for VS 2008, the directory is "C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas"
  2. Associate NAnt build files (.build) with the Visual Studio XML editor. This can be done in one of two ways:
    • Create a registry merge file with the following contents and merge it in your registry:
      Windows Registry Editor Version 5.00
    • Make the association through Visual Studio:
      • Open any Visual Studio solution
      • Add a NAnt build file to it
      • Right click on the .build file and choose "Open With"
      • Select "XML Editor" and click on "Set as Default"
  3. Almost there. The last thing is to add the "xmlns" (namespace) attribute to the "project" tag of your build file. If you have copied the NAnt schema file (nant.xsd) to the right place, adding the "xmlns" attribute should list the NAnt schema as one of the available choices. The end result should look like:
  4. And Voila! Start typing some XML and you should see a list of NAnt tasks and attributes.

1 comment:

  1. I'm gleaning some basics off your site while I teach myself NAnt. :-)

    BTW, you have to copy the nant.xsd schema file to

    C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas

    To get these instructions to work with Visual Studio 2008 - should have been obvious, but I tripped over this for a bit, trying to figure out why the xmlns= attribute wasn't bringing up the NAnt schema in auto-complete.


// //]]>