John Lam 1997 — 2026

Happy together: NUnit 2.1 and NAnt 0.8.3

I figured I’d tackle a simple project while Matthew sleeps this afternoon: making NAnt 0.8.3 and NUnit 2.1 live happily with one another. Out of the box, this certainly isn’t the case since NAnt 0.8.3 was built against NUnit 2.0.6 and it contains hard references to version 2.0.6 of nunit.framework.dll.

Here’s a set of steps that should make things work:

  1. Copy nunit.framework.dll from your NUnit 2.1 install directory (typically \Program Files\NUnit V2.1\bin) to your NAnt install directory (mine lives in \Tools\NAnt\bin).
  2. The RemoteTestRunner class has changed between NUnit 2.0 and NUnit 2.1. This requires a change to the NUnit2TestDomain.cs file from the NAnt 0.8.3 distribution. There are references to an Initialize() method, which has been removed in NUnit 2.1. Below is a code frag that shows the new code and the old code. This code frag begins at line 67 of NUnit2TestDomain.cs:
                if (testcase != null) {
                    runner.TestName = testcase;
                    runner.TestFileName = assemblyFile;
//                    runner.Initialize(testcase, assemblyFile);
                } else {
                    runner.TestFileName = assemblyFile;
//                    runner.Initialize(assemblyFile);
                }
  1. Build NAnt by running “nant” on the command line from the NAnt directory.

If you are using Win2K3, and you haven’t installed V1.0 of the frameworks, you’re going to be in for a bit more pain:

  1. Reset NAnt to use the 1.1 Framework paths. To do this, edit the NAnt.exe.config file (located in NAnt\bin). Find the frameworks XML element and change the default attribute’s value to “net-1.1”.
  2. When you build NAnt, it will try and run a set of unit tests against the newly built version of NAnt. However, the NAnt.exe.config file is created during the build process, and the unit tests will default to using V1.0 of the frameworks. To fix this problem, edit NAnt.exe.config in the build directory (Nant\build\nant-0.8.3.50105-debug\bin on my machine) and change the frameworks XML element’s default attribute’s value to “net-1.1”.
  3. Re-build NAnt, and the unit tests should all pass.

If you’ve completed the above steps, don’t forget to replace the files in Nant\bin with the files you just compiled!

1 archived reader comment

phil haack (2003-10-06)

I’m just curious if you’ve compared the upcoming MSBuild and/or BuildIT (documented in MS Patterns and Practices book “Team Development with Visual Studio.NET and Visual SourceSafe”) with NAnt.

Right now I’m a big fan of NAnt and I’ve written a custom Fortran Solution task (don’t ask). ;) I’m curious where NAnt will fit in when MS releases MSBuild.