Reputation: 471
I'm running a few API tests on azure devops agent and getting this warning error message
2021-05-21T13:42:29.0650201Z ##[error]DiscoveryMessage : Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process exited with error: Cannot use file stream for [C:\a\r1\a\_Automation-Build\drop\TestAutomation.UI.PageObject\bin\Debug\netcoreapp3.1\testhost.deps.json]: No such file or directory
2021-05-21T13:42:29.0661479Z ##[debug]Processed: ##vso[task.logissue type=error;]DiscoveryMessage : Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process exited with error: Cannot use file stream for [C:\a\r1\a\_Automation-Build\drop\TestAutomation.UI.PageObject\bin\Debug\netcoreapp3.1\testhost.deps.json]: No such file or directory
2021-05-21T13:42:29.0663114Z A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Program Files\dotnet'.
2021-05-21T13:42:29.0663661Z Failed to run as a self-contained app.
2021-05-21T13:42:29.0664305Z - The application was run as a self-contained app because 'C:\a\r1\a\_Automation-Build\drop\TestAutomation.UI.PageObject\bin\Debug\netcoreapp3.1\testhost.runtimeconfig.json' was not found.
2021-05-21T13:42:29.0665393Z - If this should be a framework-dependent app, add the 'C:\a\r1\a\_Automation-Build\drop\TestAutomation.UI.PageObject\bin\Debug\netcoreapp3.1\testhost.runtimeconfig.json' file and specify the appropriate framework.
2021-05-21T13:42:29.0666319Z . Please check the diagnostic logs for more information.
2021-05-21T13:42:29.0667169Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.ThrowOnTestHostExited(Boolean testHostExited)
2021-05-21T13:42:29.0668081Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings)
2021-05-21T13:42:29.0668810Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler)
I've also went through that article https://www.gitmemory.com/issue/microsoft/vstest/2218/540508574 and i'm not sure how i can apply test files selection with test plan
option instead test assemblies
Upvotes: 12
Views: 10554
Reputation: 16609
This usually happens because the test runner picks up its own related files, plus potentially other dlls you don't need to test, and it cannot test them properly.
You can usually see which files it is trying to test in the build output, something like this:
[command]C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe
"@D:\a\_temp\picufy3glth.tmp"
Microsoft (R) Test Execution Command Line Tool Version 17.3.0-preview-20220626-01 (x64)
Copyright (c) Microsoft Corporation. All rights reserved.
vstest.console.exe "D:\a\1\s\Proj\bin\Release\net6.0\MyTestProject.dll"
"D:\a\1\s\Proj\bin\Release\net6.0\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll"
"D:\a\1\s\Proj\bin\Release\net6.0\es\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
We had this issue on a basic .NET v6 test project (but contained in a solution multi-targeting other framework versions).
We solved it by adding exclusions for all "testhost" files and "Microsoft" dlls to the testfiles listing:
!**\testhost*.*
!**\Microsoft*.dll
Upvotes: 4
Reputation: 35514
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Program Files\dotnet'.
Based on the error message, you could refer to this Github ticket.
Here are the methods you could try:
Change the Test files path in VSTest task(From **\*test*.dll
to **\*test.dll
).
Remove references from one test assembly to another
Update Microsoft.NET.Test.SDK to 16.6.1
Upvotes: 6