情况如下:我正在尝试使用我称之为“TestProject”的测试项目来运行单元测试。它正在另一个项目中测试一个类,我将其称为“Class1”和“Project1”。
Project1 在运行时对各种 dll 进行一些动态延迟加载,我将其称为“TheDynamicDLLs”。Project1 通过查看相对于它自己的构建输出路径的目录来找到这些 dll。
问题的第一部分出现在 TestProject 引用 Project1 时。显然,它将新建的 Project1.dll 复制到其 OWN 构建目录,然后当 Project1.dll 在相对于其位置的路径中查找 TheDynamicDLLs 时,它找不到它们,因为它是从 TestProject 的位置运行的,而不是它的自己的。
为了解决这个问题,我去了 TestProject 的引用,右键单击 Project1 引用,然后打开它的属性。然后我将“复制本地”设置为“假”。我还确保引用的“路径”属性与 Project1 的构建路径相同。
现在我有一个新问题,我什至无法弄清楚它是什么。每当我运行单元测试时,它都会失败并报告“System.IO.FileNotFoundException:无法加载文件或程序集[信息将 Project1 命名为无法找到的程序集]”。
此外,当我尝试调试单元测试时,而不是仅仅运行它,它永远不会引发异常、抱怨或任何事情,从而阻止我找到有关该问题的任何进一步信息。我在测试报告中也找不到任何有用的信息。
这是带有名称的完整测试报告,出于保密目的,这些名称已被换掉:
Test Name: Class1_Tests
Test FullName: TestProject.TestClass.Class1_Tests
Test Source: c:\Code\Solution1\Tests\TestProject\TestClass.cs : line 175
Test Outcome: Failed
Test Duration: 0:00:00.0348455
Result Message:
Test method TestProject.TestClass.Class1_Tests threw exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Project1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.=== Pre-bind state information ===
LOG: DisplayName = Project1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Code/Solution1/Tests/TestProject/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : TestProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Code\Solution1\Tests\TestProject\bin\Debug\TestProject.dll.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Code/Solution1/Tests/TestProject/bin/Debug/Project1.DLL.
LOG: Attempting download of new URL file:///C:/Code/Solution1/Tests/TestProject/bin/Debug/Project1/Project1.DLL.
LOG: Attempting download of new URL file:///C:/Code/Solution1/Tests/TestProject/bin/Debug/Project1.EXE.
LOG: Attempting download of new URL file:///C:/Code/Solution1/Tests/TestProject/bin/Debug/Project1/Project1.EXE.
Result StackTrace: at TestProject.TestClass.Class1_Tests()
从日志来看,TestProject 似乎仍在尝试从其 OWN #$%^ing 构建路径加载 Project1 的 dll,尽管我明确告诉它不要复制本地。(咕噜……)
我究竟做错了什么?