DevOps 测试程序集:无法加载文件或程序集
DevOps Test Assemblies: Could not load file or assembly
我目前正在 Azure DevOps 中设置 CI 管道。
在此管道中,我想 运行 在解决方案中找到的所有测试。
但是,管道在测试步骤失败并出现以下错误:
A total of 81 test files matched the specified pattern.
##[error]An exception occurred while invoking executor 'executor://mstestadapter/v2': Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
##[error]Stack trace:
##[error] at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.PlatformServiceProvider.get_AdapterTraceLogger()
##[error] at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.MSTestExecutor.RunTests(IEnumerable`1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
##[error] at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.RunTestsWithSources.InvokeExecutor(LazyExtension`2 executor, Tuple`2 executorUriExtensionTuple, RunContext runContext, IFrameworkHandle frameworkHandle)
##[error] at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.<>c__DisplayClass48_0.<RunTestInternalWithExecutors>b__0()
##[error] at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformThread.<>c__DisplayClass0_0.<Run>b__0()
##[error]--- End of stack trace from previous location where exception was thrown ---
##[error] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
##[error] at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformThread.Run(Action action, PlatformApartmentState apartmentState, Boolean waitForCompletion)
##[error] at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.TryToRunInSTAThread(Action action, Boolean waitForCompletion)
##[error] at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTestInternalWithExecutors(IEnumerable`1 executorUriExtensionMap, Int64 totalTests)
##[error]Inner exception: Strong name validation failed. (Exception from HRESULT: 0x8013141A)
我发现它无法加载程序集 Microsoft.VisualStudio.TestPlatform 很有趣,因为我没有在任何地方引用它。
我所拥有的参考资料如下:
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
测试任务配置如下:
steps:
- task: VSTest@2
displayName: 'Test Assemblies'
inputs:
testAssemblyVer2: |
**$(BuildConfiguration)\*test*.dll
**$(BuildConfiguration)\**\*test*.dll
!**\obj\**
runTestsInIsolation: true
codeCoverageEnabled: true
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
以下是管道概览:
所以,经过一番挖掘后,我让它开始工作了。
我更改了管道以使用 .Net Core 任务而不是 Visual Studio 构建。然后就成功了。
以下是新管道测试部分的概述:
这是测试任务的 Yaml:
steps:
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: '$(Parameters.TestProjects)'
arguments: '--configuration $(BuildConfiguration)'
我目前正在 Azure DevOps 中设置 CI 管道。 在此管道中,我想 运行 在解决方案中找到的所有测试。
但是,管道在测试步骤失败并出现以下错误:
A total of 81 test files matched the specified pattern.
##[error]An exception occurred while invoking executor 'executor://mstestadapter/v2': Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
##[error]Stack trace:
##[error] at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.PlatformServiceProvider.get_AdapterTraceLogger()
##[error] at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.MSTestExecutor.RunTests(IEnumerable`1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
##[error] at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.RunTestsWithSources.InvokeExecutor(LazyExtension`2 executor, Tuple`2 executorUriExtensionTuple, RunContext runContext, IFrameworkHandle frameworkHandle)
##[error] at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.<>c__DisplayClass48_0.<RunTestInternalWithExecutors>b__0()
##[error] at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformThread.<>c__DisplayClass0_0.<Run>b__0()
##[error]--- End of stack trace from previous location where exception was thrown ---
##[error] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
##[error] at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformThread.Run(Action action, PlatformApartmentState apartmentState, Boolean waitForCompletion)
##[error] at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.TryToRunInSTAThread(Action action, Boolean waitForCompletion)
##[error] at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTestInternalWithExecutors(IEnumerable`1 executorUriExtensionMap, Int64 totalTests)
##[error]Inner exception: Strong name validation failed. (Exception from HRESULT: 0x8013141A)
我发现它无法加载程序集 Microsoft.VisualStudio.TestPlatform 很有趣,因为我没有在任何地方引用它。 我所拥有的参考资料如下:
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
测试任务配置如下:
steps:
- task: VSTest@2
displayName: 'Test Assemblies'
inputs:
testAssemblyVer2: |
**$(BuildConfiguration)\*test*.dll
**$(BuildConfiguration)\**\*test*.dll
!**\obj\**
runTestsInIsolation: true
codeCoverageEnabled: true
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
以下是管道概览:
所以,经过一番挖掘后,我让它开始工作了。
我更改了管道以使用 .Net Core 任务而不是 Visual Studio 构建。然后就成功了。
以下是新管道测试部分的概述:
这是测试任务的 Yaml:
steps:
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: '$(Parameters.TestProjects)'
arguments: '--configuration $(BuildConfiguration)'