Comments (15)
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.
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 <OutputType>exe</OutputType>
property to your .csproj?
from vstest.
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:
dotnet test Foo.Tests/bin/Release/net8.0/publish/Foo.Tests.dll --verbosity normal --logger trx;LogFileName=Laerdal.Assets.Installers.Tests.trx --results-directory TestResults
This works on localdev but fails when running it in Azure with the following error message:
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
##[error]Testhost process for source(s) 'D(0,0): Error : A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'D:\a\1\s\Foo\bin\Release\net8.0\publish\'.
Testhost process for source(s) 'D : \a\1\s\Foo\bin/Release/net8.0/publish/Foo.Tests.dll' exited with error : A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'D:\a\1\s\Foo\bin\Release\net8.0\publish\'. [D:\a\1\s\Laerdal.Scripts\Laerdal.Builder.targets]
Failed to run as a self-contained app.
- The application was run as a self-contained app because 'D:\a\1\s\Foo\bin\Release\net8.0\publish\testhost.runtimeconfig.json' was not found.
- If this should be a framework-dependent app, add the 'D:\a\1\s\Foo\bin\Release\net8.0\publish\testhost.runtimeconfig.json' file and specify the appropriate framework.
. Please check the diagnostic logs for more information.
Test Run Aborted.
Results File: D:\a\1\s\TestResults\Laerdal.Assets.Installers.Tests.trx
##[error]Laerdal.Scripts\Laerdal.Builder.targets(151,9): Error MSB3073: The command "..." exited with code 1.
D:\a\1\s\Laerdal.Scripts\Laerdal.Builder.targets(151,9): error MSB3073: The command "..." exited with code 1.
Using the following nugets:
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0-preview-24080-01" />
<PackageReference Include="Microsoft.TestPlatform" Version="17.10.0-preview-24080-01" />
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="17.10.0-preview-24080-01" />
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
from vstest.
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:
<PropertyGroup>
<Params>$(Params) "Foo.Tests.csproj"</Params>
<Params>$(Params) --logger:"trx;LogFileName=Foo.Tests.trx"</Params>
<Params>$(Params) --verbosity:"minimal"</Params>
<Params>$(Params) --configuration:"Release"</Params>
<Params>$(Params) --results-directory:"TestResults"</Params>
</PropertyGroup>
<Message Importance="High" Text=""/>
<Message Importance="High" Text="dotnet test $(Params)"/>
<Message Importance="High" Text=""/>
<Exec Command=" dotnet test $(Params) "
EchoOff="false"
ConsoleToMSBuild="true"
WorkingDirectory="$(RootFolder)"/>
The moral for me is that 'publish' doesn't quite publish all assets needed for the test-suite to be run properly.
from vstest.
@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 . :/
from vstest.
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.
from vstest.
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.
Yes, runtimeconfig.json and deps.json are both in the same directory my Tests.dll is in
from vstest.
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 ...
PS: The Foo.Tests.csproj looks like so:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>12.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<!-- https://stackoverflow.com/questions/38085430/the-library-hostpolicy-dll-was-not-found -->
<!-- <GenerateRuntimeConfigDevFile>true</GenerateRuntimeConfigDevFile>-->
<OutputType>exe</OutputType>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="FluentAssertions" Version="7.0.0-alpha.3" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0-preview-24080-01" />
<PackageReference Include="Microsoft.TestPlatform" Version="17.10.0-preview-24080-01" />
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="17.10.0-preview-24080-01" />
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Foo.csproj" />
</ItemGroup>
</Project>
Additional factoids:
- The Foo.csproj is a netstandard2.1 project
- I'm running the pipeline on Windows-2022 on Azure if that's of any consequence.
- I also gave 'dotnet vstest' a shot but no dice (no tests get discovered)
- I upgraded xunit to version 2.6.6 still no joy (no tests get discovered)
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:
xunit.runner.reporters.netcoreapp10.dll
xunit.runner.utility.netcoreapp10.dll
xunit.runner.visualstudio.testadapter.dll
I have no idea why this happens.
from vstest.
from vstest.
How do you build this? Do you do just dotnet publish on the project / solution, or something else?
I have a .targets msbuild-script that builds both Foo.csproj and Foo.csproj like so:
<!-- RESTORE NUGETS -->
<MSBuild Projects="Foo.csproj" Targets="Restore"/>
<!-- COMPILE AND PACK -->
<MSBuild Projects="Foo.csproj" Targets="Build"/>
<MSBuild Projects="Foo.Tests.csproj" Targets="Restore"/>
<MSBuild Projects="Foo.Tests.csproj" Targets="Publish"/>
<Exec Command=" dotnet test "Foo.Tests/bin/Release/net8.0/publish/Foo.Tests.dll" --verbosity normal --logger "trx;LogFileName=Foo.Tests.trx" --results-directory "TestResults" "
EchoOff="true"
ConsoleToMSBuild="true"
WorkingDirectory="$(RootFolder)"/>
from vstest.
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):
<PropertyGroup>
<Params>$(Params) "Foo.Tests/bin/Release/net8.0/publish/Laerdal.Assets.Installers.Tests.dll"</Params>
<Params>$(Params) --verbosity:normal</Params>
<Params>$(Params) --logger:"trx;LogFileName=Foo.Tests.trx"</Params>
<Params>$(Params) --results-directory:"TestResults"</Params>
<Params>$(Params) --test-adapter-path:"C:\Users\VssAdministrator\.nuget\packages\xunit.runner.visualstudio\2.5.6\build\net6.0"</Params>
<!-- also tried -->
<!-- <Params>$(Params) --test-adapter-path:"/c/Users/VssAdministrator/.nuget/packages/xunit.runner.visualstudio/2.5.6/build/net6.0"</Params> -->
</PropertyGroup>
<Exec Command=" dotnet test $(Params) "
EchoOff="false"
ConsoleToMSBuild="true"
WorkingDirectory="$(RootFolder)"/>
I'm absolutely baffled by this
from vstest.
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 msbuild /t:Publish
on the project).
from vstest.
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
msbuild /t:Publish
on the project).
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.
from vstest.
I also ran into this recently and had to add more exclusions to testAssemblyVer2
. in particular !**\Microsoft.Testing.Extensions.*.dll
- task: VSTest@3
displayName: VSTest
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*test*.dll
!**\testhost.dll
!**\*TestAdapter.dll
!**\*TestPlatform*.dll
!**\Microsoft.Testing.Extensions.*.dll
!**\obj\**
from vstest.
@DFeder maybe you could benefit from having the filter search just your bin:
**\bin\**\*Tests.dll
**\bin\**\*Test.dll
from vstest.
Maybe. It's unfortunate that the docs show examples of stuff that just doesn't work in many cases.
from vstest.
Related Issues (20)
- CA2022 errors in src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs
- Unable to debug individual google tests in visual studio 2022 cmake project
- Unescaping f# method names HOT 4
- Microsoft.NET.Test.Sdk should migrate to System.Text.Json HOT 4
- The InProcDataCollector's TestCaseStart/TestCaseStop methods are not always called.
- Unable to find a datacollector with friendly name 'Screen and Voice Recoder' HOT 1
- Missing .trx Files in Azure Build Pipeline from VSTest task HOT 3
- TRX file generated but with no test results - Solution on how to fix the version mismatch in VSTEST@2 in Azure classic version
- Thread safety is not working properly on .net 6.0 and .net 8.0 for mstest HOT 4
- VSTest doesn't support multiple versions of a test framework HOT 2
- VSTest after 1st Run will re-run failed tests but instead runs all tests
- failOnMinTestsNotRun doesn't appear to work correctly
- Update maxversiontested so xaml islands can be used in vstest.console.exe HOT 3
- dotnet test output quality is degraded in .NET 9 Preview 3 SDK HOT 3
- oft has the most Steps to produce the VSTEST_HOST_DEBUG environment variable
- Add documentation of environment variables
- Code coverage seems to be broken in version 17.10.0 HOT 1
- Test Execution behaves differently from vstest ado task vs vstest.console.exe HOT 2
- Cannot exclude auto-generated code from code coverage with .runsettings file HOT 1
- ()mtet_
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vstest.