Building with NAnt (and NUnit, and NCover, and NCoverExplorer)

A while back, I wrote a blog post, A quick introduction to Nant, which gave, well, a quick introduction to building C# libraries using NAnt.

Since then, I’ve been using NAnt to do a lot more — notably, to run unit tests and to report on test coverage (using NCover and NCoverExplorer). The usage is pretty straightforward, and I think you’ll see how each step builds on the previous step.

  • To run a default build (excluding unit tests): nant
  • To build all projects and unit tests (but don’t run : nant build-tests
  • To build all projects and unit tests, and run tests using NUnit: nant test
  • To build all projects and unit tests, and run tests using NCover to generate coverage reports: nant cover
  • To build all projects and unit tests, run tests using NCover to generate coverage reports, and open those reports in NCoverExplorer: nant coverex

The sample below is my NAnt build file. A few notes first.

  • There are only two projects referenced: Project1 and Project1.Tests. Repeat the appropriate sections to build against additional projects.
  • nunit-console.exe is expected to be in the system path.
  • nunit-console.exe, ncover.console.exe, and ncoverexplorer.exe are expected to be in the system path. I recommend you download and install TestDriven.Net to have all of these in a convenient place.

Now, on to the build file. It should be self-explanatory, but I added some XML comments for your convenience.

. . . → Read More: Building with NAnt (and NUnit, and NCover, and NCoverExplorer)

A quick introduction to NAnt

There’s lots of open source libraries out there which have become ubiquitous in today’s world. One of those is NAnt, a .Net build tool.

I’ve wanted to use NAnt for a while but never had a sufficient pressing need to do so. After forcing myself to get familiar with it so I can build the latest Castle trunk, I decided to add it to a few of my own projects. What follows is a summary of that experience, and some helpful NAnt tips for notices.

The first step is to set up your development environment. Download the NAnt binaries for the latest release (0.85 as of this writing) and extract those files somewhere on your computer (it went to c:\dev\utils\nant on my computer). Add the NAnt bin folder to your system path so you can run nant.exe from any command prompt.

Now that you have NAnt on your system, you need to create a build file. Build files are XML . . .

→ Read More: A quick introduction to NAnt