NUnit 没有运行 VisualStudio2010代码

我正在尝试加载一个 Visual Studio 2010 beta dll 到 NUnit GUI 中,我得到了一个弹出错误。

此程序集由比当前加载的运行库更新的运行库生成,无法加载。您可能试图使用比 NUnit 当前运行版本更高版本的 CLR 加载程序集生成。

如何强制可执行文件在.NET4下运行?

31489 次浏览

I've downloaded the NUnit 2.5 source and opened the VS2008 solution in the VS2010 beta. Once the conversion finished I opened all the projects and changed the target framework setting for all the projects to ".NET Framework 4.0". I then built the solution without any errors. I can now use the NUnit GUI app to run tests built for .NET 4.0. I've not done exhaustive testing of this build so there may be problems, but for my purposes it works fine.

Update: It is not necessary to rebuild NUnit. I discovered that if you add the following to the relevant NUnit config file you can run a test dll built for .NET 4.0.

Under <configuration> add:

<startup>
<supportedRuntime version="v4.0.30319" />
</startup>

and under <runtime> add:

<loadFromRemoteSources enabled="true" />

The proposed solution worked great for getting NUnit to run. Unfortunately, when I then got to my code coverage step, NCover started giving me:

Profiled process terminated. Profiler connection not established.

The best solution I found to this was to just use the "-x86" version of NUnit with NCover:

NCover.Console.exe nunit-console-x86.exe --additional params--

Works now.

With .NET 4 being released, I used

<supportedRuntime version="v4.0.30319" />

in the NUnit 2.5.4 exe.config instead of requiredRuntime, and the loadFromRemoteResources tag as shown above and all worked well. Thanks!

In NUnit 2.5.5 you can specify in the command line the option /framework=net-4.0 and it is compatible with the new assemblies generated with the release of the latest VS2010.

If you experience this issue after upgrading to nunit 2.5.5 then you will need to upgrade nant to the latest version for me it was .91 alpha.

I ran into the very same error message while running NUnit 2.4.8. As I had not upgraded in some time I installed the current NUnit (v2.5.9) and found that it now supports VS2010 assemblies. So if you have newly encountered this error check your NUnit version: as of December 2010 (or so) the only thing you need to do is upgrade NUnit.

To find your .net 4 version from the Visual [C# 2010 Express, or which ever] go to the Visual application's "About" under the menu's Help item. It should show up as the version under the Microsoft .NET Framework line on the top right hand side of the window.

I found usefull to start from NUnit Application Template. It support VS C# Express, allows debugging tests and contains precompiled NUnit for .NET 4.0. Thank to author new test project gets ready with one click.

As of NUnit 2.5.10 you can enable visual studio support in the GUI runner:

Tools-> Settings-> IDE Support

After that I was able to successfully attach to the nunit-agent.exe process which runs your assembly in a .NET 4.0 app domain

You don't have to modify any file

just open this file and everything will work just fine

C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-x86.exe