console.exe程序集解析失败
本文关键字:失败 程序集 exe console | 更新日期: 2023-09-27 18:11:44
我有一个UnitTests.dll
, Common.dll
被引用(都是用VS2015构建的)。
我的目录结构如下:
C:'Test'
- UnitTests.dll
- UnitTests.runsettings
C:'Bin'
- Common.dll
UnitTests.runsettings
含量如下:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<TargetPlatform>x64</TargetPlatform>
</RunConfiguration>
<MSTest>
<MapInconclusiveToFailed>True</MapInconclusiveToFailed>
<CaptureTraceOutput>False</CaptureTraceOutput>
<DeleteDeploymentDirectoryAfterTestRunIsComplete>False</DeleteDeploymentDirectoryAfterTestRunIsComplete>
<DeploymentEnabled>False</DeploymentEnabled>
<AssemblyResolution>
<Directory Path="C:'Bin'" includeSubDirectories="true" />
</AssemblyResolution>
</MSTest>
</RunSettings>
我调用测试:
C:'Test> vstest.console.exe UnitTests.dll /settings:UnitTests.runsettings /inIsolation
vstest.console.exe
指的是C:'Program Files (x86)'Microsoft Visual Studio 14.0'Common7'IDE'CommonExtensions'Microsoft'TestWindow' vest .console.exe.
我收到以下错误:
Starting test execution, please wait...
Failed TestMethod1
Error Message:
Test method UnitTests.UnitTest1.TestMethod1 threw exception: System.IO.FileNotFoundException: Could not load file or assembly 'Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Stack Trace:
at UnitTests.UnitTest1.TestMethod1()
更多,启用Fusion Log:
Starting test execution, please wait...
Failed TestMethod1
Error Message:
Test method UnitTests.UnitTest1.TestMethod1 threw exception: System.IO.FileNotFoundException: Could not load file or assembly 'Common, 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 = Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Test
LOG: Initial PrivatePath = NULL
Calling assembly : UnitTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
=== LOG: This bind starts in default load context.
LOG: Using application configuration file:
C:'Program Files (x86)'Microsoft Visual Studio 14.0'Common7'IDE'CommonExtensions'Microsoft'TestWindow'vstest.executionengine.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:'Windows'Microsoft.NET'Framework64'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:/Test/Common.DLL.
LOG: Attempting download of new URL file:///C:/Test/Common/Common.DLL.
LOG: Attempting download of new URL file:///C:/Test/Common.EXE.
LOG: Attempting download of new URL file:///C:/Test/Common/Common.EXE.
Stack Trace:
at UnitTests.UnitTest1.TestMethod1()
我是否面临某种缓存问题?如何说服vstest.console.exe
寻找C:'Bin'
内部的依赖关系(理论上由AssemblyResolution
元素指向)?
更新:
在连接时作为bug提交给微软(带有再现步骤-在底部的DETAILS选项卡下)。
程序集解析的现有限制,以及强制使用DeploymentItem
属性,根本无法扩展。冗余的维护成本(开发人员被迫手动跟踪运行单元测试所需的依赖项)给测试带来了摩擦。由于这种摩擦而出现的任何问题都很难排除。
Runsettings MSDN文档似乎在Directory
元素中有一个拼写错误,属性path
必须是小写才能工作。如果指定
<AssemblyResolution>
<Directory path="C:'Bin'" includeSubDirectories="true" />
</AssemblyResolution>
为所有必需的文件设置deploymenttemattribute:
[DeploymentItem("Common.dll")]
[DeploymentItem("Common2.dll")]
[TestMethod]
public void TestFoo()
{
Bar();
}