visual-studio NUnit 未运行 Visual Studio 2010 代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/930438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:34:44  来源:igfitidea点击:

NUnit isn't running Visual Studio 2010 code

visual-studio-2010visual-studiodebuggingnunit

提问by Ball

I'm trying to load a Visual Studio 2010 beta dll into the NUnit GUI. I get a popup error.

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

This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. You may be attempting to load an assembly build with a later version of the CLR than the version under which NUnit is currently running.

此程序集由比当前加载的运行时更新的运行时构建,无法加载。您可能正在尝试使用比 NUnit 当前运行的版本更高的 CLR 版本加载程序集版本。

How do I force an executable to run under .NET 4?

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

回答by Charles Cook

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.

我已经下载了NUnit 2.5源码,并在VS2010 beta中打开了VS2008解决方案。转换完成后,我打开所有项目并将所有项目的目标框架设置更改为“.NET Framework 4.0”。然后我构建了没有任何错误的解决方案。我现在可以使用 NUnit GUI 应用程序运行为 .NET 4.0 构建的测试。我没有对这个版本进行详尽的测试,所以可能会有问题,但就我的目的而言,它运行良好。

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.

更新:没有必要重建 NUnit。我发现如果您将以下内容添加到相关的 NUnit 配置文件中,您可以运行为 .NET 4.0 构建的测试 dll。

Under <configuration> add:

在 <configuration> 下添加:

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

and under <runtime> add:

并在 <runtime> 下添加:

<loadFromRemoteSources enabled="true" />

回答by pelazem

With .NET 4 being released, I used

随着 .NET 4 的发布,我使用了

<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!

在 NUnit 2.5.4 exe.config 而不是 requiredRuntime 中,并且 loadFromRemoteResources 标记如上所示,一切正常。谢谢!

回答by darky

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

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

回答by Cristian T

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

NUnit 2.5.5 中,您可以在命令行中指定选项/framework=net-4.0,它与最新 VS2010 发布时生成的新程序集兼容。

回答by Scott Marlowe

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

提议的解决方案非常适合让 NUnit 运行。不幸的是,当我进入我的代码覆盖步骤时,NCover 开始给我:

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 的“-x86”版本的 NUnit:

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

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

Works now.

现在工作。

回答by Dan Paden

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.

要从 Visual [C# 2010 Express, or which ever] 中找到您的 .net 4 版本,请转到菜单帮助项下的 Visual 应用程序的“关于”。它应该显示为窗口右上角的 Microsoft .NET Framework 行下的版本。

回答by Michael Sorens

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 onlything you need to do is upgrade NUnit.

我在运行 NUnit 2.4.8 时遇到了同样的错误消息。由于我有一段时间没有升级,我安装了当前的 NUnit (v2.5.9) 并发现它现在支持 VS2010 程序集。因此,如果您新遇到此错误,请检查您的 NUnit 版本:截至 2010 年 12 月(左右),您唯一需要做的就是升级 NUnit。

回答by CrackerHyman

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

从 NUnit 2.5.10 开始,您可以在 GUI 运行器中启用 Visual Studio 支持:

Tools-> Settings-> IDE Support

工具-> 设置-> IDE 支持

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

之后,我能够成功附加到 nunit-agent.exe 进程,该进程在 .NET 4.0 应用程序域中运行您的程序集

回答by Ernest

I foundusefull 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.

发现从 NUnit Application Template开始很有用。它支持 VS C# Express,允许调试测试并包含用于 .NET 4.0 的预编译 NUnit。感谢作者,新的测试项目一键准备就绪。

回答by Adam

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.

如果您在升级到 nunit 2.5.5 后遇到此问题,那么您需要将 nant 升级到我的最新版本,它是 .91 alpha。