Search code examples
azure-devopsazure-pipelinesxunit

The library 'hostpolicy.dll' required to execute the application was not found


I am receiving the following error when running unit tests in 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'.  

In my build pipeline I have 6 .NetCore xunit test projects and 1 .net standard xunit project.

I am trying to execute all unit tests before publishing to my org feed.

I tried to exclude the testhost.dll from being picked by VsTest as other have and succeed but for me it doesn't seem to work..

My config for VSTest tasks:

- 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)'

Solution

  • After reading the logs properly I found that the VsTest task was picking the following dlls: Xamarin.Forms.Core.UnitTests.dll, Xamarin.Forms.Xaml.UnitTests.dll.

    All I had to do was to change the search pattern from **\*Tests.dll to **\*.Tests.dll as all my unit test projects were following this convention: Org.Base.Project.Tests.