NAnt Tasks

NAnt allows you to combine tasks to automate your build process. Tasks can be grouped together into targets, and targets can call other targets (much like functions/methods in any other language).

If you need to do something that cannot be done by an existing task, you have two options:

  1. Create a target that combines existing tasks;
  2. Write a custom NAnt task.

Option 1 has some limitations; you can create a target, give it a name, and call it in your script by using <call target="myTarget"/>. However, the target cannot specify a list of parameters, so you have to rely on setting (agreed) properties before calling the target if you want to pass information to it.

Option 2 allows you to create a new task for NAnt. They are considerably more effort to write and maintain as they need knowledge of a .Net language (e.g., C#). If you want to do something that cannot be done by existing tasks, then they are probably your only option.

Sometimes you want to write a task that can be done with existing tasks (e.g., check a target is up to date; if it isn't, code-generate some code, compile it, and register the assembly in the GAC), but without resorting to C#. We thought a middle ground would be nice, so we wrote a couple of custom NAnt tasks that allow you to create new custom NAnt tasks that are written using regular NAnt script.

Enter NAntScript

NAntScript is an open source project we wrote to allow NAnt users to script custom NAnt tasks using only existing NAnt tasks (no C# required).

Two custom tasks are provided:

  • taskdef - defines a scripted custom task;
  • tdc - compiles a collection of taskdef nodes in files into an assembly.

Now you can write custom NAnt tasks without resorting to C#.

Submit this story to DotNetKicks Shout it