未找到 NUnit 程序集

发布于 2024-07-06 02:05:20 字数 1302 浏览 4 评论 0原文

我以前使用过 NUnit,但已经有一段时间了,而且从来没有在这台机器上使用过。 我在 Program Files 下解压了 2.4.8 版本,并且在尝试加载测试时不断收到此错误。

无法加载文件或程序集“nunit.framework,Version=2.4.8.0,Culture=neutral,PublicKeyToken=96d09a1eb7f44a77”或其依赖项之一。 系统找不到指定的文件**

为了简化问题,我编译了最基本的可能的测试文件。

using NUnit.Framework;

namespace test
{
    [TestFixture]
    public class Tester
    {
        [Test]
        public void ATest()
        {
            Assert.IsTrue(false, "At least the test ran!");
        }
    }
}

我已将“C:\Program Files\NUnit-2.4.8-net-2.0\bin”添加到我的路径中(并重新启动)。 请注意,如果我将测试程序集复制到该文件夹​​中,则

C:\Program Files\NUnit-2.4.8-net-2.0\bin>nunit-console test.dll

可以工作,但

C:\Program Files\NUnit-2.4.8-net-2.0\bin>nunit-console c:\dev\nunit_test\test.dll

C:\dev\nunit_test>nunit_console test.dll

因上述错误而失败。

想必我可以通过将 NUnit.Framework DLL 文件复制到项目的 bin 文件夹中来解决这个问题,但我不记得过去必须这样做。 此外,我在 GUI 中遇到了同样的错误。 GUI 不应该知道框架位于哪里(即在同一个文件夹中)吗?

我没有使用 Visual Studio。 我使用以下行来编译测试项目。

%windir%\Microsoft.NET\Framework\v2.0.50727\csc.exe /r:"C:\Program Files\NUnit-2.4.8-net-2.0\bin\nunit.framework.dll" /t:library /out:test.dll test.cs

我尝试了 .msi 和 .zip 文件,结果相同。

I've used NUnit before, but not in a while, and never on this machine. I unzipped version 2.4.8 under Program Files, and I keep getting this error when trying to load my tests.

Could not load file or assembly 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The system cannot find the file specified**

In order to simplify the problem, I've compiled the most basic possible test file.

using NUnit.Framework;

namespace test
{
    [TestFixture]
    public class Tester
    {
        [Test]
        public void ATest()
        {
            Assert.IsTrue(false, "At least the test ran!");
        }
    }
}

I've added "C:\Program Files\NUnit-2.4.8-net-2.0\bin" to my PATH (and rebooted). Note that if I copy the test assembly into that folder, then

C:\Program Files\NUnit-2.4.8-net-2.0\bin>nunit-console test.dll

works, but

C:\Program Files\NUnit-2.4.8-net-2.0\bin>nunit-console c:\dev\nunit_test\test.dll

and

C:\dev\nunit_test>nunit_console test.dll

fail with the above error.

Presumably I could get around this by copying the NUnit.Framework DLL file into my project's bin folder, but I don't remember having to do this in the past. Moreover, I get the same error in the GUI. Shouldn't the GUI know where the framework is located (that is, in the same folder)?

I'm not using Visual Studio. I use the following line to compile the test project.

%windir%\Microsoft.NET\Framework\v2.0.50727\csc.exe /r:"C:\Program Files\NUnit-2.4.8-net-2.0\bin\nunit.framework.dll" /t:library /out:test.dll test.cs

I tried both the .msi and the .zip file with the same result.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

岁月流歌 2024-07-13 02:05:20

确保您已添加对 nunit.framework 的引用。 如果有,请确保该引用的属性将复制本地属性设置为 true。

Make sure you have added a reference to nunit.framework. If you have, then make sure the properties of that reference have the copy local property set to true.

爺獨霸怡葒院 2024-07-13 02:05:20

我遇到了同样的问题,并且我使用 NUnit-2.4.8-net-2.0.msi 进行安装。 扩展“添加到 GAC”评论,这就是我所做的:

  • 打开“Visual Studio 命令提示符”(通常:确保 gacutil 在您的路径中)并: cd "C:\Program Files\NUnit 2.4.8\bin"

  • 从 GAC 中取消注册您的 NUnit 条目。 您可以通过查找在 GAC 中注册的 NUnit 条目来完成此操作:

    <前><代码>gacutil /l | 查找/i“nunit”> 温度.bat && 记事本温度.bat

  • 在 nunit.core 和 nunit.framework 行前面添加“gacutil /uf”,即:

    gacutil /uf nunit.core,版本=2.4.2.0,文化=中性,PublicKeyToken=96d09a1eb7f44a77 
    
      gacutil /uf nunit.framework,版本=2.4.2.0,文化=中性,PublicKeyToken=96d09a1eb7f44a77 
      
  • 运行 .bat 文件以删除它们:
    temp.bat

  • 注册您需要的 NUnit DLL 文件:

    gacutil /i nunit.core.dll 
    
      gacutil /i nunit.framework.dll 
      

I had the same problem, and I had installed using NUnit-2.4.8-net-2.0.msi. Expanding on the "add to the GAC" comment, here's what I did:

  • Open your "Visual Studio command prompt (generally: make sure gacutil is in your path) and: cd "C:\Program Files\NUnit 2.4.8\bin"

  • Unregister your NUnit entries from the GAC. You can do this by finding the NUnit entries registered in the GAC:

    gacutil /l | find /i "nunit" > temp.bat && notepad temp.bat
    
  • Prepend the nunit.core and nunit.framework lines with "gacutil /uf", i.e.:

    gacutil /uf nunit.core,Version=2.4.2.0,Culture=neutral,PublicKeyToken=96d09a1eb7f44a77
    
    gacutil /uf  nunit.framework,Version=2.4.2.0,Culture=neutral,PublicKeyToken=96d09a1eb7f44a77
    
  • Run your .bat file to remove them:
    temp.bat

  • Register the NUnit DLL files you need:

    gacutil /i nunit.core.dll
    
    gacutil /i nunit.framework.dll
    
稀香 2024-07-13 02:05:20

如果使用 NUnit-2.4.8-net-2.0.msi 安装,NUnit 程序集将添加到 GAC

您还可以通过从 Visual Studio 2005 命令提示符运行 gacutil 来手动重新安装。

If you install using NUnit-2.4.8-net-2.0.msi, the NUnit assemblies are added to the GAC.

You can also reinstall manually by running gacutil from the Visual Studio 2005 command prompt.

不弃不离 2024-07-13 02:05:20

请注意,当前的 NUnit 安装 (2.5.10) 不会在 GAC 中自动注册。

如果必须使用 GAC,请通过 gacutil /i 注册,其中 nunitframeworkpath 通常是 %Program Files%\NUnit\net-2.0\framework\ nunit-framework

Note that the current NUnit installation (2.5.10) doesn't register itself automatically in the GAC.

If you must use GAC, register it via gacutil /i <nunitframeworkpath> where nunitframeworkpath is usually %Program Files%\NUnit\net-2.0\framework\nunit-framework.

如梦 2024-07-13 02:05:20

今天,当我尝试将新的测试程序集添加到现有的 NUnit 测试项目时,收到此错误消息。 看来我的测试项目对相同的 nunit.framework.dll 程序集有多个路径引用。

如果您的 NUnit 项目中有多个测试程序集,您可能需要验证测试项目中 nunit.framework 引用的 Path 属性。 一旦我使它们匹配,错误消息就消失了。

I got this error message today when I tried to add a new test assembly to an existing NUnit test project. It seems that my test projects had multiple path references to identical nunit.framework.dll assemblies.

If you have more than one test assembly in your NUnit project, you may want to verify the Path property of the nunit.framework reference in your test projects. Once I made them match, the error message went away.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文