microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
207 stars 7 forks source link

[BUG] Devkit server fails to start with dotnet installed via snap #605

Open dibarbet opened 8 months ago

dibarbet commented 8 months ago

Describe the Issue

This was originally reported on the C# extension side here - https://github.com/dotnet/vscode-csharp/issues/6513 (with a fix in the upcoming release).

When dotnet is installed via snap on ubuntu, the devkit server fails to start

Starting Spawn .NET server...
Starting Open a solution...
Starting Open a solution with environment service...
Starting Clear environment...
Using preinstalled .NET runtime at "/usr/bin/snap"
.NET server STDERR: You must install .NET to run this application.

App: /home/dibarbet/.vscode/extensions/ms-dotnettools.csdevkit-0.5.150-linux-x64/components/vs-green-server/platforms/linux-x64/node_modules/@microsoft/visualstudio-server.linux-x64/Microsoft.VisualStudio.Code.Server
Architecture: x64
App host version: 7.0.5
.NET location: Not found

Learn about runtime installation:
https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=ubuntu.22.04-x64&apphost_version=7.0.5

.NET server exited with 131

From the investigation in https://github.com/dotnet/vscode-csharp/issues/6513 the basic cause is that the dotnet on the path is symlinked to /usr/bin/snap which is the snap executable. However devkit is expecting it to find the dotnet executable in the dotnet installation directory.

dibarbet@dibarbet-Virtual-Machine:~$ which dotnet
/snap/bin/dotnet
dibarbet@dibarbet-Virtual-Machine:~$ realpath /snap/bin/dotnet
/usr/bin/snap

Alternatively, running ls -l

dibarbet@dibarbet-Virtual-Machine:~$ ls -l /snap/bin/dotnet
lrwxrwxrwx 1 root root 17 Oct 10 13:43 /snap/bin/dotnet -> dotnet-sdk.dotnet
dibarbet@dibarbet-Virtual-Machine:~$ ls -l /snap/bin/dotnet-sdk.dotnet 
lrwxrwxrwx 1 root root 13 Oct 10 13:43 /snap/bin/dotnet-sdk.dotnet -> /usr/bin/snap

The real location of the dotnet install is something like /snap/dotnet-sdk/221/dotnet or /snap/dotnet-sdk/current/dotnet

The fix we made on the C# extension side was to instead read the output of the runtime path (from dotnet --list-runtimes and look 2 directories up for the executable. Since they use the assembly path this should always output the 'real' dotnet installation directory. Ran this by the runtime/sdk folks who said it should be fine See https://github.com/dotnet/vscode-csharp/issues/6513#issuecomment-1756249012

C# extension PR: https://github.com/dotnet/vscode-csharp/pull/6515

Steps To Reproduce

Repro steps

  1. Install dotnet on ubuntu via snap, e.g. snap install dotnet-sdk --classic --channel=7.0
  2. Open a project in vscode
  3. Note the failure in the C# devkit output window:

Expected Behavior

Devkit server starts

Environment Information

Dotnet info

.NET SDK:
 Version:   7.0.402
 Commit:    791db8e2d8

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  22.04
 OS Platform: Linux
 RID:         ubuntu.22.04-x64
 Base Path:   /snap/dotnet-sdk/224/sdk/7.0.402/

Host:
  Version:      7.0.12
  Architecture: x64
  Commit:       4a824ef37c

.NET SDKs installed:
  7.0.402 [/snap/dotnet-sdk/224/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.12 [/snap/dotnet-sdk/224/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.12 [/snap/dotnet-sdk/224/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
github-actions[bot] commented 3 months ago

This issue has been marked as stale after 14 days of inactivity. @[ @AArnott @], could you please take a look?

AArnott commented 3 months ago

@lifengl should probably look at this as he owns the SDK/runtime acquisition now.

ivanjx commented 2 weeks ago

im also having the same issue. this is the dotnet --info result from the vscode's integrated terminal:

.NET SDK:
 Version:           8.0.300
 Commit:            326f6e68b2
 Workload version:  8.0.300-manifests.c1c70047
 MSBuild version:   17.10.4+10fbfbf2e

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  24.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /snap/dotnet-sdk/245/sdk/8.0.300/

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.5
  Architecture: x64
  Commit:       087e15321b

.NET SDKs installed:
  8.0.300 [/snap/dotnet-sdk/245/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.5 [/snap/dotnet-sdk/245/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.5 [/snap/dotnet-sdk/245/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/snap/dotnet-sdk/current]

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

but vscode does not seem to be able to run the same command correctly:

Failed to find dotnet info from path, falling back to acquire runtime via ms-dotnettools.vscode-dotnet-runtime
Error running dotnet --info: Error: Command failed: dotnet --info
Aborted (core dumped)

Aborted (core dumped)

Dotnet path: /home/x/.config/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/8.0.6~x64/dotnet
Activating C# + C# Dev Kit + C# IntelliCode...
waiting for named pipe information from server...
[stdout] {"pipeName":"/tmp/6442fe69.sock"}
received named pipe information from server
attempting to connect client to server...
client has connected to server
[Info  - 9:57:04 AM] [Program] Language server initialized

also i dont know if it matters but the vscode is also installed via snap (with --classic confinement too same as the dotnet):

name:      code
summary:   Code editing. Redefined.
publisher: Visual Studio Code (vscode✓)
store-url: https://snapcraft.io/code
contact:   https://twitter.com/code
license:   unset
description: |
  Visual Studio Code is a new choice of tool that combines the
  simplicity of a code editor with what developers need for the core
  edit-build-debug cycle.
commands:
  - code
  - code.url-handler
snap-id:      Ht0aUHi7ofh9Fbwh6m7jUN2pAy6kzBiu
tracking:     latest/stable
refresh-date: 5 days ago, at 00:46 WIB
channels:
  latest/stable:    5437499f 2024-06-19 (162) 327MB classic
  latest/candidate: ↑                               
  latest/beta:      ↑                               
  latest/edge:      ↑                               
installed:          611f9bfc            (161) 327MB classic