NUnit的:无法加载程序集nunit.framework加载、程序、NUnit、nunit

2023-09-04 11:11:31 作者:凋谢ㄋ青春つ

试图执行单元测试,引用nunit.framework失败:

Trying to execute a unit test which references nunit.framework fails:

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

我的方案如下: Visual Studio 2010的TFS​​ C#和.NET Framewok V4.0 NUnit的2.6.0.12051

My scenario is the following: Visual Studio 2010 TFS C# and .NET Framewok v4.0 NUnit 2.6.0.12051

详细说明: 我有一个测试项目,它引用某些DLL,一个是nunit.framework.dll中。 这个DLL(nunit.framework.dll中),使其指向NUnit的2.6.0.12051的安装文件夹。 我执行NUnit的(而不是从Visual Studio),通过NUnit的-x86.exe程序,一旦lauched我加载测试项目(它是一个类库,DLL)。 NUnit的尝试加载,但上述错误解释appears.Test项目编译好了,该dll被正确生成。同时测试项目的目标是到.NET框架4.0版。

Detailed explanation: I have a test project which references some dlls, one is nunit.framework.dll. This dll (nunit.framework.dll), points to the folder where nunit 2.6.0.12051 is installed. I execute NUnit (not from visual studio), through nunit-x86.exe and once lauched I load the test project(it is a class library, dll). Nunit tries to load but the error above explained appears.Test project compiles Ok, the dll is generated correctly. Also test project is targeting to .NET Framework v4.0.

推荐答案

请尝试重定向大会在配置文件绑定:

Please, try to redirect the assembly binding in your configuration file:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="library-name" publicKeyToken="hex-key" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-2.5.10.11092" newVersion="2.5.10.11092"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>

更改库名来nunit.framework参考和六角键为适当的值。

Change "library-name" to nunit.framework reference and "hex-key" to the appropriate value.

您可能已经像上面的记录。你应该适应动态网页的值。

You may have already a record like the above. You should just adapt the "newVersion" value.