This wasn't obvious to Patrick and I, but it is in retrospect. When you're using NAnt's NUnit2 tasks to run NUnit tests, all the assembly versions need to line up. However, sometimes the version of your test framework might not match up with the version that NAnt was built with. For example, you might have tests that were compiled (and, as such, reference) NUnit 2.0.6 or 2.1.4. However, you're using NAnt 0.85 which runs tests with NUnit 2.2.0.0. Not only that, but the NUnit test runner creates a new AppDomain for each test. That means you can't do a binding (version) redirect with a NAnt.exe.config, because the AppDomain gets a funky name of its own and has its own binding redirect rules that the loader follows.
So, you have to create a test.config file. You can name it anything you want, like mydefaulttest.config, and it'll look something like this:
<configuration> ... <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="Neutral" /> <bindingRedirect oldVersion="2.0.6.0" newVersion="2.2.0.0" /> <bindingRedirect oldVersion="2.1.4.0" newVersion="2.2.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> ... </configuration>
Then you need to TELL the NUnit2 NAnt task that you want to use this specific config file:
<nunit2> <formatter type="Plain" /> <test assemblyname="MyProject.Tests.dll" appconfig="mydefaulttest.config" /> </nunit2>
Then the NUnit2 task will make sure the newly created AppDomain uses (or promotes) the correct version and your tests won't fail to load.
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. I am a failed stand-up comic, a cornrower, and a book author.
Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.