dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 669 forks source link

Debugging test in multitargeted project doesn't work #2759

Open aggieben opened 5 years ago

aggieben commented 5 years ago

Environment data

dotnet --info output:

14:40 $ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.1.500
 Commit:    b68b931422

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.14
 OS Platform: Darwin
 RID:         osx.10.14-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.1.500/

Host (useful for support):
  Version: 2.1.6
  Commit:  3f4f8eebd8

.NET Core SDKs installed:
  2.1.500 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

VS Code version: 1.25.1 C# Extension version: 1.15.2

Steps to reproduce

  1. Create a class library with <TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>;
  2. create an xUnit test project with the same TargetFrameworks.
  3. set "csharp.unitTestDebuggingOptions": { "type": "coerclr" } in config
  4. use CodeLens "debug test" link to try to debug a test.

Expected behavior

CoreCLR debugger attaches to test runner and test runs under debugger.

Actual behavior

Error in debug console:

The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The program '[33552] mono' has exited with code 0 (0x0).
gregg-miskelly commented 5 years ago

@akshita31 @rchande Sounds like the debugger is being told to debug the wrong process, or the xUnit is somehow being configured to run under mono instead of .NET Core.

@aggieben does your XUnit project have <TargetFrameworks> declared in that same order?

aggieben commented 5 years ago

@gregg-miskelly Yes. Here's what's in the project under test (TrueMyth.csproj):

<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>

and in the xUnit test project (TrueMyth.Test.csproj):

<TargetFrameworks>net461;netcoreapp2.1</TargetFrameworks>
gregg-miskelly commented 5 years ago

@aggieben If you swap the order so 'netstandard2.0' goes first, does it work?

aggieben commented 5 years ago

I did three things and now it seems to be working; I'm not sure which of the three things might have helped:

  1. I reversed the order of the frameworks to netcoreapp2.1;net461 and netstandard2.0;net461, respectively
  2. I ran into this problem, so I set <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
  3. Set sdk version 2.1.500 in my global.json (which I bizarrely wasn't previously using)

My guess is No. 1 was the thing that did this (thanks for the suggestion), but I really don't know.