Azure 管道任务 VSTest@2 因错误而失败 - 无法加载文件或程序集“Microsoft.VisualStudio.TestPlatform.Common.resources”

时间:2021-03-03 20:26:49

标签: azure-devops azure-pipelines azure-pipelines-build-task azure-deployment azure-pipelines-yaml

我创建了 .Net Core 3.1 API 测试用例项目。我的项目有以下 nugget 包。

<块引用>
  • Microsoft.NET.Test.Sdk 15.3.0
  • 最小起订量 4.16.1
  • xunit - 2.4.1
  • xunit.runner.visualstudio - 2.4.3

单元测试项目在VS 2019中正常执行,我所有的测试用例都通过了。在部署 yaml 文件中,我有以下代码。

- task: VSTest@2
 - inputs:
     platform: '$(buildPlatform)'
     configuration: '$(buildConfiguration)'

此任务因大量错误而失败

2021-03-03T18:33:16.4990294Z [MSTest][Discovery][D:\a\1\s\API\MyProject.ApiTests\bin\Release\netcoreapp3.1\cs\Microsoft.VisualStudio.TestPlatform.Common.resources.dll] Failed to discover tests from assembly D:\a\1\s\API\MyProject.ApiTests\bin\Release\netcoreapp3.1\cs\Microsoft.VisualStudio.TestPlatform.Common.resources.dll. Reason:Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.Common.resources' or one of its dependencies. The system cannot find the file specified.
2021-03-03T18:33:16.5032225Z [MSTest][Discovery][D:\a\1\s\API\MyProject.ApiTests\bin\Release\netcoreapp3.1\cs\Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll] Failed to discover tests from assembly D:\a\1\s\API\MyProject.ApiTests\bin\Release\netcoreapp3.1\cs\Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll. Reason:Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.ObjectModel.resources' or one of its dependencies. The system cannot find the file specified.
2021-03-03T18:33:16.5033961Z [MSTest][Discovery][D:\a\1\s\API\MyProject.ApiTests\bin\Release\netcoreapp3.1\de\Microsoft.TestPlatform.CommunicationUtilities.resources.dll] Failed to discover tests from assembly D:\a\1\s\API\MyProject.ApiTests\bin\Release\netcoreapp3.1\de\Microsoft.TestPlatform.CommunicationUtilities.resources.dll. Reason:Could not load file or assembly 'Microsoft.TestPlatform.CommunicationUtilities.resources' or one of its dependencies. The system cannot find the file specified.

等等。

我尝试升级/降级 Microsoft.NET.Test.Sdk 版本,但没有成功。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:2)

在我们的项目中,我们做了几件事:确保安装了正确的工具集,并具体说明测试路径:

          - task: VisualStudioTestPlatformInstaller@1
            displayName: 'Install Visual Studio Test Platform'
            inputs:
              packageFeedSelector: 'nugetOrg'
              versionSelector: 'latestStable'
          - task: VSTest@2
            displayName: 'Run Unit Tests'
            inputs:
              vsTestVersion: 'toolsInstaller'    
              # our test projects all have ".Tests" in the name
              testAssemblyVer2: '**/bin/$(buildConfiguration)/*.Tests.dll'
              platform: '$(buildPlatform)'
              configuration: '$(buildConfiguration)'
              codeCoverageEnabled: true
              runTestsInIsolation: true

答案 1 :(得分:0)

WaitingForGuacamole 的上述回答与将 Microsoft.NET.Test.Sdk 升级到 16.9.1 一起工作。谢谢。