Azure Devops Pipeline Azure Repos Git .Net Error in Tests Failed to run as a self-contained app
Asked Answered
F

1

5

I have a .Net solution with multiple projects, including a test project. When I create a pipeline for my solution using Azure Devops templates, with the connect Azure Repos Git and configure ASP.Net Core (.Net Framework), I get the following yml file:

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- main

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*test*.dll
      !**\*TestAdapter.dll
      !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

When I run the pipline and reaches the VSTest Task, after running the tests, it gives me the following error:

##[error]Testhost process for source(s) 'D:\a\1\s\Fazer.UITests\bin\Release\net6.0\Microsoft.TestPlatform.PlatformAbstractions.dll' 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]Failed to run as a self-contained app.
##[error]  - The application was run as a self-contained app because 'D:\a\1\s\Fazer.UITests\bin\Release\net6.0\testhost.runtimeconfig.json' was not found.
##[error]  - If this should be a framework-dependent app, add the 'D:\a\1\s\Fazer.UITests\bin\Release\net6.0\testhost.runtimeconfig.json' file and specify the appropriate framework.
##[error]. Please check the diagnostic logs for more information.

How can I fix this?

Frontlet answered 20/12, 2022 at 18:6 Comment(0)
F
13

After a while searching for the solution, I found out that all I had to do was to change the line **\*test*.dll to **\*Tests.dll for the key testAssemblyVer2 in the task VSTest@2.

Before:

- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
  --> **\*test*.dll
      !**\*TestAdapter.dll
      !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

After:

- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
  --> **\*Tests.dll
      !**\*TestAdapter.dll
      !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

Then the pipeline runned sucesssfully!

Frontlet answered 20/12, 2022 at 18:6 Comment(2)
Hello @VitaZhang-MSFT thank you for your kind comment, I will accept it but i need to wait 2 days after posting it, also if it somehow helped you and of course you don't mind, you can upvote ;)Frontlet
Thank you @VitaZhang-MSFT, I am upvoting you as well :)Frontlet

© 2022 - 2024 — McMap. All rights reserved.