visualstudio.xunit icon indicating copy to clipboard operation
visualstudio.xunit copied to clipboard

UseCommonOutputDirectory=true breaks `dotnet test`

Open lilith opened this issue 3 years ago • 1 comments

Setting UseCommonOutputDirectory to true breaks dotnet test, when using dotnet 6.0 runner. This occurs when TargetFrameowrk = net472, net48, and net6.0, but not net5.0.

Partial workaround

    <PropertyGroup Condition="!$(MSBuildProjectName.EndsWith('Tests'))">
        <UseCommonOutputDirectory>true</UseCommonOutputDirectory>
    </PropertyGroup>

Example .csproj that fails

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

    <PropertyGroup>
        <UseCommonOutputDirectory>true</UseCommonOutputDirectory>    
    </PropertyGroup>

    <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
    <PackageReference Include="xunit" Version="2.4.2" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="3.1.2">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>
    
</Project>

run dotnet test

For net472 and net48, the error is:

PS C:\Users\lilith\imazen\resizer\PrimeService.Tests> dotnet test
  Determining projects to restore...
  All projects are up-to-date for restore.
  PrimeService.Tests -> C:\Users\lilith\imazen\resizer\PrimeService.Tests\bin\Debug\net472\PrimeService.Tests.dll
Test run for C:\Users\lilith\imazen\resizer\PrimeService.Tests\bin\Debug\net472\PrimeService.Tests.dll (.NETFramework,Version=v4.7.2)
Microsoft (R) Test Execution Command Line Tool Version 17.2.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
No test is available in C:\Users\lilith\imazen\resizer\PrimeService.Tests\bin\Debug\net472\PrimeService.Tests.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

For net6.0, the error is:

PS C:\Users\lilith\imazen\resizer\PrimeService.Tests> dotnet test
  Determining projects to restore...
  Restored C:\Users\lilith\imazen\resizer\PrimeService.Tests\PrimeService.Tests.csproj (in 499 ms).
  PrimeService.Tests -> C:\Users\lilith\imazen\resizer\PrimeService.Tests\bin\Debug\net6.0\PrimeService.Tests.dll
Test run for C:\Users\lilith\imazen\resizer\PrimeService.Tests\bin\Debug\net6.0\PrimeService.Tests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.2.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Testhost process exited with error: Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Microsoft.VisualStudio.TestPlatform.TestHost.Program.Main(String[] args)
. Please check the diagnostic logs for more information.

Test Run Aborted.


Delete line <UseCommonOutputDirectory>true</UseCommonOutputDirectory> to see test execute properly.

lilith avatar Aug 21 '22 00:08 lilith

Also reported here: https://github.com/dotnet/sdk/issues/27320

lilith avatar Aug 21 '22 01:08 lilith

Closing this an external issue.

bradwilson avatar May 21 '23 20:05 bradwilson