-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"The library 'hostpolicy.dll' required to execute the application was not found" - Azure vstest #4743
Comments
Could you check that there are both runtimeconfig.json and deps.json files next to your test dll? Their name should start with the name of your dll. |
Facing the same issue with a dotnet8 / xunit project in Azure. In my localdev I have the test-dlls published properly under 'bin/Release/net8.0/publish/'. I then invoke:
This works on localdev but fails when running it in Azure with the following error message:
Using the following nugets:
|
This seems strange to reference There is most likely no Foo.Tests.runtimeconfig.json in the output folder. Which means your test project is not built as exe for some reason. Can you try adding |
It was just me experimenting with adding a few more nugets just to be sure I'm not missing something.
Yes you're right - in Azure I create the file manually:
This still doesn't resolve the issue completely however (see the output I get at the bottom)
I get the following error:
I had to use the following in the .csproj:
And I added a 'Main' inside Program.cs on the test project. When the tests are run on Azure however I get this:
While on localdev tests are discovered and run just fine. Hmmm ... PS: The Foo.Tests.csproj looks like so:
Additional factoids:
It turns out that the warning I get about the tests not being discoverable is because the following dlls are not outputted in the output directory when running the pipeline in Azure:
I have no idea why this happens. |
How do you build this? Do you do just dotnet publish on the project / solution, or something else?
…________________________________
Od: Kyriakos Sidiropoulos ***@***.***>
Odesláno: Wednesday, January 31, 2024 6:59:59 PM
Komu: microsoft/vstest ***@***.***>
Kopie: Comment ***@***.***>; Subscribed ***@***.***>
Předmět: Re: [microsoft/vstest] "The library 'hostpolicy.dll' required to execute the application was not found" - Azure vstest (Issue #4743)
This seems strange to reference <PackageReference Include="Microsoft.TestPlatform" Version="17.10.0-preview-24080-01" /> but it should not hurt anything, maybe you are using it to get the whole TP into your .nuget cache.
It was just me experimenting with adding a few more nugets just to be sure I'm not missing something.
There is most likely no Foo.Tests.runtimeconfig.json in the output folder. Which means your test project is not built as exe for some reason.
Yes you're right - in Azure I create the file manually:
bin\Release\net8.0\publish\Foo.Tests.runtimeconfig.json
This still doesn't resolve the issue completely however (see the output I get at the bottom)
Can you try adding <OutputType>exe</OutputType> property to your .csproj?
I get the following error:
CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [
I had to use the following in the .csproj:
<OutputType>exe</OutputType>
<GenerateProgramFile>false</GenerateProgramFile>
And I added a 'Main' inside Program.cs on the test project. When the tests are run on Azure however I get this:
No test is available in D:\a\1\s\Foo.Tests/bin/Release/net8.0/publish/Foo.Tests.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
While on localdev tests are discovered and run just fine. Hmmm ...
—
Reply to this email directly, view it on GitHub<#4743 (comment)> or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABLYLYIYWVFGVKWP7CNVF3DYRKBCBBFKMF2HI4TJMJ2XIZLTSOBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTAVFOZQWY5LFUVUXG43VMWSG4YLNMWVXI2DSMVQWIX3UPFYGLLDTOVRGUZLDORPXI6LQMWWES43TOVSUG33NNVSW45FGORXXA2LDOOJIFJDUPFYGLKTSMVYG643JORXXE6NFOZQWY5LFVA3DENZXGQ3TENUCUR2HS4DFUVUXG43VMWSXMYLMOVS2UMJZHA2DCNRRHAZTRJ3UOJUWOZ3FOKTGG4TFMF2GK>.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
I have a .targets msbuild-script that builds both Foo.csproj and Foo.csproj like so:
|
Even if I specify the test-adapter-path explicitly to have it point to the local nuget-folder in the filesystem, it's still unable to discover the tests (I get the same warning):
I'm absolutely baffled by this |
The original error is coming from the fact that runtimeconfig.json is not present. I would start by generating a binlog from the build locally and on the server and comparing what is going on with runtimeconfig.json. Binary log viewer should make this rather easy, because you will see the targets that are skipped, and why. All the other errors can be explained also by a "broken" build, so I would start investigating why runtimeconfig.json is not generated first. I would also try deleting all the bins before every attempt, to make sure that you are not seeing some previous state leaving files in the folder (and making it work). Your project references all the right nugets, and when I try it locally it builds just fine (I am building via |
I did a deep-clean on localdev (deleted bin and obj folders) and re-run my command line scriptlet: You're right the problem can be reproduced on my localdev in this fashion. If I build through my IDE first and then run my scriptlet I can't reproduce this problem anymore - it seems the IDE is taking care of copying additional dlls into the output folders somehow. |
Ok here's how I solved it: I simply reverted to calling 'dotnet test' directly on the .csproj while making sure to specify the correct configuration in the build script - somehow this solved all the problems I was witnessing:
The moral for me is that 'publish' doesn't quite publish all assets needed for the test-suite to be run properly. |
I also ran into this recently and had to add more exclusions to - task: VSTest@3
displayName: VSTest
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*test*.dll
!**\testhost.dll
!**\*TestAdapter.dll
!**\*TestPlatform*.dll
!**\Microsoft.Testing.Extensions.*.dll
!**\obj\** |
Maybe. It's unfortunate that the docs show examples of stuff that just doesn't work in many cases. |
@dfederm Thanks for pointing this out. I've made this to be the default in vstest@2 task on azdo some time ago. And even updated the doc for vstest@2. But now there is a new version of the task and it does not have that change. Made a bug here: microsoft/azure-pipelines-tasks#19555 unfortunately we don't own this task . :/ |
The change to the filter that prevents this was done, but regressed in azdo, unfortunately this is out of our hands, issue was filed here: microsoft/azure-pipelines-tasks#19555 The filter above ( #4743 (comment) ) is what we are recommending to use in azdo, and it was documented for VSTest@2 but not for the regressed @3. |
Description
Hello, I have an automated E2E test project on Azure and have a build pipeline set up to run our test suite
I am trying to set up a release pipeline in order to run selected automated tests directly from Azure Test Plans, following this guide:
https://learn.microsoft.com/en-us/azure/devops/test/run-automated-tests-from-test-hub?view=azure-devops
My build pipeline publishes an artifact containing the test binaries and the release pipeline downloads the binaries artifact ok, also the automated test cases are associated to the case in the Test Plan
But when I go to run the test I get a 'hostpolicy.dll' library missing error (see error message / logs below)
I tried following the steps outlined in this response but have not been able to get it working but yet:
#2427 (comment)
Steps to reproduce
Expected behavior
Selected test(s) from Test Plans should run
Actual behavior
Test exits with error: 'hostpolicy.dll' required to execute the application was not found
Diagnostic logs
2023-11-08T18:38:35.3500242Z ##[error]DiscoveryMessage : Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process for source(s) 'C:\agent01_work\r1\a\binaries\Ts.TestAutomation.Web.Tests.dll' exited with error: Cannot use file stream for [C:\agent01_work\r1\a\binaries\testhost.deps.json]: No such file or directory
2023-11-08T18:38:35.3507332Z A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\agent01_work\r1\a\binaries'.
2023-11-08T18:38:35.3509600Z Failed to run as a self-contained app.
2023-11-08T18:38:35.3511962Z - The application was run as a self-contained app because 'C:\agent01_work\r1\a\binaries\testhost.runtimeconfig.json' was not found.
2023-11-08T18:38:35.3517076Z - If this should be a framework-dependent app, add the 'C:\agent01_work\r1\a\binaries\testhost.runtimeconfig.json' file and specify the appropriate framework.
2023-11-08T18:38:35.3519328Z . Please check the diagnostic logs for more information.
2023-11-08T18:38:35.3522035Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.ThrowOnTestHostExited(IEnumerable
1 sources, Boolean testHostExited) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs:line 520 2023-11-08T18:38:35.3525746Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable
1 sources, String runSettings) in //src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs:line 2942023-11-08T18:38:35.3529864Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.InitializeDiscovery(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler, Boolean skipDefaultAdapters) in //src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs:line 149
2023-11-08T18:38:35.4866569Z ##[error]DiscoveryMessage : Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process for source(s) 'C:\agent01_work\r1\a\binaries\Ts.TestAutomation.Web.Tests.dll' exited with error: . Please check the diagnostic logs for more information.
2023-11-08T18:38:35.4962672Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.ThrowOnTestHostExited(IEnumerable
1 sources, Boolean testHostExited) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs:line 520 2023-11-08T18:38:35.4979792Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable
1 sources, String runSettings) in //src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs:line 2942023-11-08T18:38:35.4987864Z at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.InitializeDiscovery(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler, Boolean skipDefaultAdapters) in //src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs:line 149
2023-11-08T18:38:35.5697915Z ##[error]DiscoveryMessage : Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process for source(s) 'C:\agent01_work\r1\a\binaries\binaries\Ts.TestAutomation.Web.Tests.dll' exited with error: Cannot use file stream for [C:\agent01_work\r1\a\binaries\binaries\testhost.deps.json]: No such file or directory
2023-11-08T18:38:35.5704704Z A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\agent01_work\r1\a\binaries\binaries'.
2023-11-08T18:38:35.5707532Z Failed to run as a self-contained app.
2023-11-08T18:38:35.5709067Z - The application was run as a self-contained app because 'C:\agent01_work\r1\a\binaries\binaries\testhost.runtimeconfig.json' was not found.
2023-11-08T18:38:35.5711018Z - If this should be a framework-dependent app, add the 'C:\agent01_work\r1\a\binaries\binaries\testhost.runtimeconfig.json' file and specify the appropriate framework.
Environment
Test project on .NET 7.0
vstest task version 2
The text was updated successfully, but these errors were encountered: