【问题标题】:The library 'hostpolicy.dll' required to execute the application was not found未找到执行应用程序所需的库“hostpolicy.dll”
【发布时间】:2020-05-25 18:28:48
【问题描述】:

在 Azure DevOps Pipelines 中运行单元测试时收到以下错误:

##[error]Testhost process exited with error: A fatal error was 
encountered. The library 'hostpolicy.dll' required to execute the 
application was not found in 'C:\Program Files\dotnet'. ##[error]. 
Please check the diagnostic logs for more information.  
##[error]Testhost process exited with error: A fatal error was 
encountered. The library 'hostpolicy.dll' required to execute the 
application was not found in 'C:\Program Files\dotnet'.  

在我的构建管道中,我有 6 个 .NetCore xunit 测试项目和 1 个 .net 标准 xunit 项目。

我正在尝试在发布到我的组织提要之前执行所有单元测试。

我试图排除 testhost.dll 像其他人一样被 VsTest 选中,并且 成功,但对我来说似乎不起作用..

我的 VSTest 任务配置:

- task: VSTest@2
  displayName: 'Running Tests NETFramework'
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      General\Exceptions.Handling.Tests\bin\Release\Exceptions.Handling.Tests.dll
      !*testhost.dll 
      !**\*testhost.dll
      !**\obj\**
      !**\xunit.runner.visualstudio.testadapter.dll
      !**\xunit.runner.visualstudio.dotnetcore.testadapter.dll
    searchFolder: './tests/UnitTests'
    platform: '$(buildPlatform)'
    configuration: '$(configuration)'


- task: VSTest@2
  displayName: 'Running Tests Framework:.NETCoreApp,Version=v3.1'
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*Tests.dll
      !*testhost.dll 
      !**\*testhost.dll
      !**\*Exceptions.Handling.Tests.dll
      !**\obj\**
      !**\xunit.runner.visualstudio.testadapter.dll
      !**\xunit.runner.visualstudio.dotnetcore.testadapter.dll
    searchFolder: './tests/UnitTests'
    otherConsoleOptions: '/Framework:.NETCoreApp,Version=v3.1 /logger:console;verbosity="normal"'
    platform: '$(buildPlatform)'
    configuration: '$(configuration)'

【问题讨论】:

    标签: azure-devops azure-pipelines xunit


    【解决方案1】:

    正确阅读日志后,我发现 VsTest 任务正在选择以下 dll:Xamarin.Forms.Core.UnitTests.dll、Xamarin.Forms.Xaml.UnitTests.dll。

    我所要做的就是将搜索模式从 **\*Tests.dll 更改为 **\*.Tests.dll,因为我所有的单元测试项目都遵循这个约定:Org.Base.Project.Tests

    【讨论】:

    猜你喜欢
    • 2017-12-21
    • 2018-11-09
    • 2016-10-31
    • 2020-08-03
    • 2021-06-05
    • 2022-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多