nant
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.
这对我和帕特里克来说并不明显,但回想起来。 当您使用NAnt的NUnit2任务运行NUnit测试时,所有程序集版本都需要排队。 但是,有时您的测试框架的版本可能与构建NAnt的版本不匹配。 例如,您可能具有已编译(并因此参考)NUnit 2.0.6或2.1.4的测试。 但是,您使用的是NAnt 0.85,它使用NUnit 2.2.0.0运行测试。 不仅如此,NUnit测试运行程序还会为每个测试创建一个新的AppDomain。 这意味着您不能使用NAnt.exe.config进行绑定(版本)重定向,因为AppDomain拥有自己的时髦名称,并且加载程序遵循其自己的绑定重定向规则。
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:
因此,您必须创建一个test.config文件。 您可以将其命名为任意名称,例如mydefaulttest.config,它的外观如下所示:
<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 NAnt任务:
<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.
然后,NUnit2任务将确保新创建的AppDomain使用(或升级)正确的版本,并且您的测试不会失败。
翻译自: https://www.hanselman.com/blog/getting-nant-085-to-get-along-with-nunit-22
nant