OmniSharp / omnisharp-roslyn

OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
MIT License
1.72k stars 417 forks source link

Unable to debug .NET 5 project on Apple M2 with vscode #2609

Closed ccidral closed 3 months ago

ccidral commented 3 months ago

Not sure if this is an issue with omnisharp or with vscode. I'm developing dotnet 5 projects on Apple M2 with vscode. Everything works perfectly, the only problem is when I start the debugger it seems that vscode/omnisharp incorrectly picks dotnet arm64 instead of the x64 to run/debug the app. More details below.

Environment data

Path to dotnet:

$ which dotnet
/usr/local/share/dotnet/dotnet

SDKs installed:

$ ls /usr/local/share/dotnet/sdk
6.0.412

$ ls /usr/local/share/dotnet/x64/sdk
5.0.408

.NET 6 info:

$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.412
 Commit:    ee124f7fe1

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  13.4
 OS Platform: Darwin
 RID:         osx.13-arm64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.412/

global.json file:
  Not found

Host:
  Version:      6.0.20
  Architecture: arm64
  Commit:       a08d9ce2ca

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

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

.NET 5 info:

$ /usr/local/share/dotnet/x64/dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.408
 Commit:    da985e2a23

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

Host (useful for support):
  Version: 5.0.17
  Commit:  6a98414363

.NET SDKs installed:
  5.0.408 [/usr/local/share/dotnet/x64/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.17 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.17 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]

VS Code version: 1.80.1 C# Extension version: 1.26.0

OmniSharp log

Starting OmniSharp server at 7/19/2023, 2:41:52 PM
    Target: /Users/ccidral/proj/example/src/Example.sln

OmniSharp server started with .NET 6.0.412
.
    Path: /Users/ccidral/.vscode/extensions/ms-dotnettools.csharp-1.26.0-darwin-arm64/.omnisharp/1.39.7-net6.0/OmniSharp.dll
    PID: 15110

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on Unknown 0.0 (Unknown)
[info]: OmniSharp.Services.DotNetCliService
        Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
[info]: OmniSharp.Services.DotNetCliService
        Using the 'dotnet' on the PATH.
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: .NET Core SDK 6.0.412 17.3.2 - "/usr/local/share/dotnet/sdk/6.0.412/"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: .NET Core SDK 6.0.412 17.3.2 - "/usr/local/share/dotnet/sdk/6.0.412/"
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/Users/ccidral/proj/example/src'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Did not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/Users/ccidral/proj/example/src/Example.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/ccidral/proj/example/src/Example.Api/Example.Api.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/ccidral/proj/example/src/Example/Example.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/ccidral/proj/example/src/Example.Abstractions/Example.Abstractions.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/ccidral/proj/example/src/Example.Repository/Example.Repository.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/ccidral/proj/example/src/Example.Tests/Example.Tests.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/ccidral/proj/example/src/Example.Client/Example.Client.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/Users/ccidral/proj/example/src'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Did not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/Users/ccidral/proj/example/src' on host 15040.
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/ccidral/proj/example/src/Example.Api/Example.Api.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/ccidral/proj/example/src/Example.Api/Example.Api.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/ccidral/proj/example/src/Example.Api/Example.Api.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/ccidral/proj/example/src/Example/Example.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/ccidral/proj/example/src/Example/Example.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/ccidral/proj/example/src/Example/Example.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/ccidral/proj/example/src/Example.Abstractions/Example.Abstractions.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/ccidral/proj/example/src/Example.Abstractions/Example.Abstractions.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/ccidral/proj/example/src/Example.Abstractions/Example.Abstractions.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/ccidral/proj/example/src/Example.Repository/Example.Repository.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/ccidral/proj/example/src/Example.Repository/Example.Repository.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/ccidral/proj/example/src/Example.Repository/Example.Repository.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/ccidral/proj/example/src/Example.Tests/Example.Tests.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/ccidral/proj/example/src/Example.Tests/Example.Tests.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/ccidral/proj/example/src/Example.Tests/Example.Tests.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/ccidral/proj/example/src/Example.Client/Example.Client.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/ccidral/proj/example/src/Example.Client/Example.Client.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/ccidral/proj/example/src/Example.Client/Example.Client.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Example.Api
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Example
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Example.Abstractions
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Example.Repository
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Example.Tests
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Example.Client

Steps to reproduce

  1. Install .NET 5 SDK package
  2. Install .NET 6 SDK package
  3. Open project in vscode
  4. Start debugging

Expected behavior

Debugging should start.

Actual behavior

Error in the debug console:

You must install or update .NET to run this application.

App: /Users/ccidral/proj/example/src/Example.Api/bin/Debug/net5.0/Example.Api.dll
Architecture: arm64
Framework: 'Microsoft.AspNetCore.App', version '5.0.0' (arm64)
.NET location: /usr/local/share/dotnet/

The following frameworks were found:
  6.0.20 at [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]

Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed

To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=5.0.0&arch=arm64&rid=osx.13-arm64
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.

Additional context

I think what happens is the vscode extension is trying to use dotnet6 arm64 to run a dotnet5 x64 binary. In other words, it seems to use /usr/local/share/dotnet/dotnet but it should probably use /usr/local/share/dotnet/x64/dotnet instead.

It seems though that it uses dotnet6 arm64 to build the binaries successfully:

Executing task: dotnet build /Users/ccidral/proj/example/src/Example.Api/Example.Api.csproj /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary 

MSBuild version 17.3.2+561848881 for .NET
  Determining projects to restore...
/usr/local/share/dotnet/sdk/6.0.412/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(29,5): warning NETSDK1138: The target framework 'net5.0' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/Users/ccidral/proj/example/src/Example.Repository/Example.Repository.csproj]
/usr/local/share/dotnet/sdk/6.0.412/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(29,5): warning NETSDK1138: The target framework 'net5.0' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/Users/ccidral/proj/example/src/Example/Example.csproj]
/usr/local/share/dotnet/sdk/6.0.412/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(29,5): warning NETSDK1138: The target framework 'net5.0' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/Users/ccidral/proj/example/src/Example.Api/Example.Api.csproj]
/usr/local/share/dotnet/sdk/6.0.412/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(29,5): warning NETSDK1138: The target framework 'net5.0' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/Users/ccidral/proj/example/src/Example.Api/Example.Api.csproj]
  Restored /Users/ccidral/proj/example/src/Example.Abstractions/Example.Abstractions.csproj (in 156 ms).
  Restored /Users/ccidral/proj/example/src/Example.Repository/Example.Repository.csproj (in 241 ms).
  Restored /Users/ccidral/proj/example/src/Example.Api/Example.Api.csproj (in 241 ms).
  Restored /Users/ccidral/proj/example/src/Example/Example.csproj (in 241 ms).
/usr/local/share/dotnet/sdk/6.0.412/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(29,5): warning NETSDK1138: The target framework 'net5.0' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/Users/ccidral/proj/example/src/Example.Api/Example.Api.csproj]
/usr/local/share/dotnet/sdk/6.0.412/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(29,5): warning NETSDK1138: The target framework 'net5.0' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/Users/ccidral/proj/example/src/Example/Example.csproj]
/usr/local/share/dotnet/sdk/6.0.412/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(29,5): warning NETSDK1138: The target framework 'net5.0' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/Users/ccidral/proj/example/src/Example.Repository/Example.Repository.csproj]
  Example.Abstractions -> /Users/ccidral/proj/example/src/Example.Abstractions/bin/Debug/netstandard2.0/Example.Abstractions.dll
  Example -> /Users/ccidral/proj/example/src/Example/bin/Debug/net5.0/Example.dll
  Example.Repository -> /Users/ccidral/proj/example/src/Example.Repository/bin/Debug/net5.0/Example.Repository.dll
  Example.Api -> /Users/ccidral/proj/example/src/Example.Api/bin/Debug/net5.0/Example.Api.dll
 *  Terminal will be reused by tasks, press any key to close it. 
ccidral commented 3 months ago

Problem solved, this solution works for me: https://github.com/dotnet/vscode-csharp/issues/6210#issuecomment-1690393842