You can use NAnt with either VB or C# to write your own custom tasks. This truly is a killer feature, once you are able to implement custom tasks in C# you can make NAnt do almost anything. This allows you to address some of NAnts weaknesses, primarly it is a build and deployment scripting platform, and not a programming platform. Using a object oriented language in conjunction makes it truly robust, and ultimately usable technology.
Extending NAnt one step further you can even create your own custom NAnt assemblies (.dll), for truly flexible tasks. We will focus on doing it in the script, becuase the name of the game is getting it done quickly, without alot of overhead, it’s scripting damnit. If we wanted something else we would just fire up Visual Studio and create a application to do it for us. If you find your self doing extensive amount of programming in NAnt you may want to reconsider NAnt for the task at hand.
First a script element needs to be created outside of a NAnt task using the needed C#.
<script language="C#" prefix="demo" ><code><![CDATA[ [Function("generateguid")]public static string getguid( ) {
return Guid.NewGuid().ToString; }]]></code></script>
<target name="Action.Print.Demo"><echo message="*** My Guid is: ${demo::generateguid()} ***" /></target>
Then the task is called by calling the prefix: ‘demo’ and the NAnt function name: ‘generateguid’. Many C# actions can be called this way, I usually use them for generating output, or other tasks nant is not great at.












