Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Installing Nant

Installing Nant is as simple as unzipping the archive file and bin directory to your Windows path. Nant expects the build file to be named filename.build. When you run Nant from the prompt, it will search for the file with a build extension and then assume it is your build file. (Multiple ".build" files cause an error to be raised.) You can override this behavior by using the –buildfile directive.

Run Nant at the command prompt with the –help option to verify that your install is up and running.

At the time of writing, there appears to be a problem with the Nant help: It's missing from the install! The Web version works fine and you can find it at http://nant.sourceforge.net/help/.

Nant Build File

The format of the Nant build is very similar to that of Ant; so much so that you can often use the Ant help! Nant is driven by an XML that contains instructions about which projects to build and the tasks to be executed. The listing below is a fragment from the sample file we will use to build our Windows Forms application.

<project name="MusicLib" default="clean">
<property name="build.dir" value="build"/>
<target name="clean">
<delete dir="${build.dir}" verbose="true" failonerror="false"/>

Before I dazzle you with our Nant sample, it'll be useful to gain some insight into the build file structure. I'll cover only the basic elements because I know how eager you are to see the sample.


The project tag is the top-level attribute in the build file and describes the project itself. The project tag has three attributes: name, default, and basedir.




The name of the project.


The default target to use when no target is supplied.


The base directory from which all path calculations are done.


The target tag defines a collection of Nant tasks and can depend on other targets. You might have a target for compiling, for example, and a target for creating an install package. Nant resolves dependencies between tasks; for example, in the case in which the "clean" task must be executed before the "compile" task.




The name of the target.


A comma-separated list of names of targets on which this target depends.


The name of the property that must be set for this target to execute.


The name of the property that must not be set for this target to execute.


A short description of this target's function.


The task is where Nant runs code and calls executables. Tasks can have multiple attributes or arguments, and it's normal practice to use properties to set some of these values.


Properties are variables that are used to set or get values in the build file. You can use them as constants to ease the burden of maintaining large build files. Properties can also be set at run-time through the –D: command-line option.

Nant comes with a number of samples, including Hello World in C#, VB, and JScript. Run these in your own time. I'm going to demonstrate how you can use Nant to build a C# Win Forms application.

  • + Share This
  • 🔖 Save To Your Account