找不到NUnit程序集

har*_*rpo 20 nunit

我之前使用过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!");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

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不应该知道框架的位置(即在同一个文件夹中)吗?

@Scott,我没有使用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

@devio,我尝试了同样结果的msi和zip.

Sco*_*sen 12

确保添加了对nunit.framework的引用.如果有,则确保该引用的属性将copy local属性设置为true.


Jef*_*ght 11

我有同样的问题,我使用NUnit-2.4.8-net-2.0.msi安装.扩展上面的"添加到gac"评论,这就是我所做的:

  • 打开"visual sudio命令提示符(通常:确保gacutil在你的路径中)和:cd"C:\ Program Files\NUnit 2.4.8\bin"

  • 从gac取消注册您的nunit条目.您可以通过查找gac中注册的nunit条目来执行此操作:

gacutil/l | find/i"nunit"> temp.bat && notepad temp.bat

  • 使用"gacutil/uf"预先添加nunit.core和nunit.framework行,即:

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

  • 运行您的bat文件以删除它们:temp.bat

  • 注册您需要的nunit dll:

gacutil/i nunit.core.dll

gacutil/i nunit.framework.dll


dev*_*vio 9

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

您也可以通过VS2005命令提示符中的runnig gacutil手动重新安装.