Peel me a Grape :: We make things work

NAnt Macrodef (.Net)

Macrodef task for NAnt

NAnt by default doesn’t have support for ant style macrodef, as discussed in
this mailing list post
.

While working for Exoftware, I was working with some clients using .net. I knocked together this custom task for NAnt to give me macrodefs. Syntax is similar to in ant, and attributes and elements are supported. Usage is like this:


To define a macro:






and calling it:



(examples taken from test build file)

Implementation Notes

The implementation uses a bit of a hack to register the new task name with NAnt – it compiles some dynamically generated code and registers the resulting assembly. So when using the task, you will see messages like:

[macrodef] Scanning assembly “66f4d2c6” for extensions.

It would be easy enough to change NAnt to avoid this step, and probably speed up the runtime also. I may look into developing this as a patch to NAnt.

Download:

  • Can download the source code from