vstest: `dotnet test` does not work for projects with custom output path
Moved from https://github.com/dotnet/cli/issues/5582 on behalf of @alecor191
Steps to reproduce
- Use VS 2017 with .csproj and create a .NET Core test project using XUnit
- Make sure to add XUnit runner package to project:
<PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
- Configure the .csproj to use a custom output path:
<BaseIntermediateOutputPath>..\..\artifacts\obj\$(MSBuildProjectName)\$(Configuration)\$(ProcessorArchitecture)\</BaseIntermediateOutputPath>
<OutputPath>..\..\artifacts\test\$(MSBuildProjectName)\$(Configuration)\$(ProcessorArchitecture)\</OutputPath>
- Run the XUnit tests from VS2017 IDE
- Run the XUnit tests using
dotnet test
Expected behavior
Both VS2017 IDE and dotnet test
should execute the XUnit tests in the test project.
Actual behavior
VS2017 IDE is able to execute the tests successfully. However, dotnet test
fails with the following warning:
Warning: The path '[...]\artifacts\test\<test_project_name>\Debug\net461' specified in the 'TestAdapterPath' does not contain any test adapters, provide a valid path and try again.
Additional info
I noticed the following:
- My guess is that the execution with
dotnet test
fails as I can’t findxunit.runner.visualstudio
assemblies in the output path (xunit.runner.visualstudio.testadapter.dll is missing). - If I remove the custom output path settings (i.e. remove both
<BaseIntermediateOutputPath>
and<OutputPath>
from the .csproj file, thendotnet test
succeeds. In fact, I see in the defaultbin
directory the files fromxunit.runner.visualstudio
package (xunit.runner.visualstudio.testadapter.dll). - Note that other NuGet package assemblies are properly copied to the custom output directory. I assume those are the dependencies that are also referenced in code; whereas the XUnit runner/testadapter assemblies are not referenced anywhere in the solution.
Environment data
dotnet --info
output:
.NET Command Line Tools (1.0.0-rc3-004530)
Product Information: Version: 1.0.0-rc3-004530 Commit SHA-1 hash: 0de3338607
Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\1.0.0-rc3-004530
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 5
- Comments: 26 (15 by maintainers)
@singhsarab At the time that I commented on this, I was working on our build process for Azure PowerShell related to using Azure DevOps. I had tried a lot of different ways to modify our build. Unfortunately, I didn’t even put enough context for myself to understand what I was referring to.
That said, I simply modified our test projects’ output folder. I ran our build and it worked appropriately. For now, I’d close this issue. If I get back to modifying our process and run into this again, I’d give more details.
@Faizan2304 Why was this closed? The OP reported this issue using the xunit runner. And, I’ve tried the latest preview,
2.4.0-beta.2.build4010
, and this issue still exists. Is it an xunit issue or a general testrunner issue?@alecor191 The issue is with msbuild and sdk and here is the solution of your problem https://github.com/dotnet/sdk/issues/980#issuecomment-285957284
You have to update your csproj similar like
Closing this issue since mono support is tracked in #679.
This is actually not a test SDK issue. @alecor191 is actually hitting https://github.com/dotnet/sdk/issues/802. @livarcocc and I hit the same thing. That issue causes the targets included in the test SDK nuget packages to not get picked up, and thereby the Main method to not get generated [amongst other issues].
I think this is something that the in-box test components may be able to check for and provide some diagnosability, though I’m not sure if that’s necessary once https://github.com/dotnet/sdk/issues/802 is fixed. I’ll leave it to the team to decide once they have a chance to think through the issue.
@livarcocc and I hit this last week in the https://github.com/dotnet/sdk when trying to port their tests to
dotnet test
. This should be an easy fix, looking for places where $(OutputPath) and $(IntermediateOutputPath)'s values are being assumed and using the property instead. It may even be a nice issue to mark asup for grabs
in case @alecor191 wants to take a shot at the fix 😃