I’ve been spending some time trying to learn how to create builds using nAnt. You can use a special nAnt element to compile your .cs source files against the C# compiler.
The above target will compile all .cs files into a single assembly called
The compile target will recurse through all the files in a subdirectory called “src” and compile all the files with a .cs extension into the final assembly, excluding the AssemblyInfo.cs file (If you have multiple projects, each one will most likely have a different “AssemblyInfo.cs” file containing assembly info for that project.) The target will try to save the assembly to a folder called “build”.
Before compiling you should ensure that the build folder exists. To do this you could create another nAnt target that creates the build directory. Here is an example.
We could now create a dependency between the compile target and the init target so that, the init target always runs before attempting to compile by adding the “depends” attribute.
Now we can run our nAnt task from the commandline:
The output will tell us what nAnt targets ran and if there were any compilation warnings or errors: