dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.87k stars 675 forks source link

C# extension doesn't work under devcontainer #4742

Closed vchirikov closed 2 years ago

vchirikov commented 3 years ago

Environment data

`dotnet --info` output: ``` b09f71e2c0a6:/_workspace# dotnet --info .NET SDK (reflecting any global.json): Version: 5.0.400 Commit: d61950f9bf Runtime Environment: OS Name: alpine OS Version: 3.13 OS Platform: Linux RID: linux-musl-x64 Base Path: /usr/share/dotnet/sdk/5.0.400/ Host (useful for support): Version: 5.0.9 Commit: 208e377a53 .NET SDKs installed: 5.0.400 [/usr/share/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 5.0.9 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.9 [/usr/share/dotnet/shared/Microsoft.NETCore.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download ```

VS Code version: 1.59.1 C# Extension version: v1.23.15

OmniSharp log

`"omnisharp.loggingLevel": "debug",` ``` Starting OmniSharp server at 9/3/2021, 11:20:48 AM Target: /_workspace/_dumps.sln OmniSharp server started. Path: /root/.vscode-server/extensions/ms-dotnettools.csharp-1.23.15/.omnisharp/1.37.15/run PID: 13284 [ERROR] Error: OmniSharp server load timed out. Use the 'omnisharp.projectLoadTimeout' setting to override the default delay (one minute). ```

Steps to reproduce

  1. dotnet new console
  2. Create dev container (I tried 5.0.400-alpine3.13 and 5.0.400-buster-slim dotnet sdk images)
  3. Open dev container environment
  4. Install C# extension there

Expected behavior

Omnisharp is started under a dev container

Actual behavior

Omnisharp doesn't start.

Additional error output

image

ps -a
PID   USER     TIME  COMMAND
    1 root      0:00 /bin/sh -c echo Container started trap "exit 0" 15  while sleep 1 & wait $!; do :; done
   92 root      0:00 /root/.vscode-server/bin/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/node /tmp/vscode-remote-containers-server-21929b26aee4891be33964a51c53d19882a636df.js
  109 root      0:00 sh /root/.vscode-server/bin/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/server.sh --log debug --force-disable-user-env --use-host-proxy --disable-telemetry --port 0 --extensions-download-dir /root/.vscode-server/extensionsCache --start-server --disable-websocket-compression
  111 root      0:06 /root/.vscode-server/bin/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/node /root/.vscode-server/bin/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/out/vs/server/main.js --log debug --force-disable-user-env --use-host-proxy --disable-telemetry --port 0 --extensions-download-dir /root/.vscode-server/e
  143 root      0:02 /vscode/vscode-server/bin/alpine/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/node /vscode/vscode-server/bin/alpine/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/out/bootstrap-fork --type=ptyHost
 9401 root      0:00 /root/.vscode-server/bin/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/node /tmp/vscode-remote-containers-server-1bd12ce1f85f8aeebaf5402d837160af3889198b.js
 9646 root      0:00 /bin/sh
12857 root      0:00 /bin/sh
12878 root      0:00 /bin/sh
13100 root      0:00 /root/.vscode-server/bin/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/node /tmp/vscode-remote-containers-server-9d32d59ba578629e8bb99396c91218d9a591fb35.js
13142 root      0:00 /root/.vscode-server/bin/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/node -e      const net = require('net');     process.stdin.pause();     const client = net.createConnection({ port: 41955 }, () => {      client.pipe(process.stdout);      process.stdin.pipe(client);     });     client.on('c
13162 root      0:00 /vscode/vscode-server/bin/alpine/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/node /vscode/vscode-server/bin/alpine/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/out/bootstrap-fork --type=watcherService
13173 root      0:00 /root/.vscode-server/bin/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/node -e      const net = require('net');     process.stdin.pause();     const client = net.createConnection({ port: 41955 }, () => {      client.pipe(process.stdout);      process.stdin.pipe(client);     });     client.on('c
13190 root      0:01 /vscode/vscode-server/bin/alpine/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/node /vscode/vscode-server/bin/alpine/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/out/bootstrap-fork --type=extensionHost --uriTransformerPath=/vscode/vscode-server/bin/alpine/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/ou
13305 root      0:00 /vscode/vscode-server/bin/alpine/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/node /vscode/vscode-server/bin/alpine/3866c3553be8b268c8a7f8c0482c0c0177aa8bfa/extensions/json-language-features/server/dist/node/jsonServerMain --node-ipc --clientProcessId=13190
13346 root      0:00 /bin/ash
13356 root      0:00 sleep 1
13357 root      0:00 ps -a
vchirikov commented 3 years ago

Found out that I need rights + gcompat and bash to run mono and omnisharp, but I still get

Unknown language in `contributes.csharp.language`. Provided value: csharp

error, although omnisharp is working:

Starting OmniSharp server at 9/3/2021, 12:23:35 PM
    Target: /_workspace/_dumps.sln

OmniSharp server started.
    Path: /root/.vscode-server/extensions/ms-dotnettools.csharp-1.23.15/.omnisharp/1.37.15/run
    PID: 6570

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on alpine 3.13.6 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 17.0.0 - "/root/.vscode-server/extensions/ms-dotnettools.csharp-1.23.15/.omnisharp/1.37.15/omnisharp/.msbuild/Current/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to '/root/.vscode-server/extensions/ms-dotnettools.csharp-1.23.15/.omnisharp/1.37.15/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 17.0.0 - "/root/.vscode-server/extensions/ms-dotnettools.csharp-1.23.15/.omnisharp/1.37.15/omnisharp/.msbuild/Current/Bin"
            CscToolExe = csc.exe
            MSBuildToolsPath = /root/.vscode-server/extensions/ms-dotnettools.csharp-1.23.15/.omnisharp/1.37.15/omnisharp/.msbuild/Current/Bin
            CscToolPath = /root/.vscode-server/extensions/ms-dotnettools.csharp-1.23.15/.omnisharp/1.37.15/omnisharp/.msbuild/Current/Bin/Roslyn
            BypassFrameworkInstallChecks = true
            MSBuildExtensionsPath = /root/.vscode-server/extensions/ms-dotnettools.csharp-1.23.15/.omnisharp/1.37.15/omnisharp/.msbuild
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/_workspace'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/_workspace/_dumps.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/_workspace/clrmd/clrmd.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/_workspace'.
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /_workspace/clrmd/clrmd.csproj
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/_workspace' on host 6265.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/_workspace/clrmd/clrmd.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/_workspace/clrmd/clrmd.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: clrmd

image

vchirikov commented 3 years ago

@nohwnd, now I use official bootstrap scripts microsoft/vscode-dev-containers and C# extension loads correctly (you still need to install gcompat on Alpine though).

For history, the solution is here: https://github.com/vchirikov/dotnet-dumps-devcontainer

nohwnd commented 3 years ago

Perfect, thanks for letting me know. We looked at this in our triage yesterday, and were surprised by this error: Unknown language incontributes.csharp.language. Provided value: csharp because that looks like something that should not happen.

/fyi @JoeRobich

vchirikov commented 2 years ago

@nohwnd , @JoeRobich looks like the same problem on 3.16 alpine even with gcompat + https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/script-library/common-alpine.sh:

image

JoeRobich commented 2 years ago

The "[ERROR]: C# Extension failed to get platform information." error is useful.

That errors is thrown early during activation: https://github.com/OmniSharp/omnisharp-vscode/blob/88ad237e1e904ad0f91d2de39c30132198a02dcb/src/main.ts#L59-L66

GetCurrent platform checks specific things on Linux platforms: https://github.com/OmniSharp/omnisharp-vscode/blob/88ad237e1e904ad0f91d2de39c30132198a02dcb/src/platform.ts#L148-L155

GetMusl should be handling exceptions: https://github.com/OmniSharp/omnisharp-vscode/blob/88ad237e1e904ad0f91d2de39c30132198a02dcb/src/platform.ts#L180-L188

GetArchitecture could be the source of this failure: https://github.com/OmniSharp/omnisharp-vscode/blob/88ad237e1e904ad0f91d2de39c30132198a02dcb/src/platform.ts#L172-L178

There was also a recent change to the locations where we look for os-release, although those errors should be caught and Unknown returned: https://github.com/OmniSharp/omnisharp-vscode/blob/88ad237e1e904ad0f91d2de39c30132198a02dcb/src/platform.ts#L24-L30

Please let me know if any of these look problematic for Alpine.

vchirikov commented 2 years ago

Inside the devcontainer based on 6.0.301-alpine3.16-amd64

> uname -m
x86_64

> ldd --version
musl libc (x86_64)
Version 1.2.3
Dynamic Program Loader
Usage: /lib/ld-musl-x86_64.so.1 [options] [--] pathname

> cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.16.0
PRETTY_NAME="Alpine Linux v3.16"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
vchirikov commented 2 years ago

Looks like the problem is here:

https://github.com/OmniSharp/omnisharp-vscode/blob/88ad237e1e904ad0f91d2de39c30132198a02dcb/src/platform.ts#L141

image

So vscode is runned under windows, but C# extension is in linux dev container and the extension doesn't support remote development.

image

Looks like some docs are here:

Supporting Remote Development and GitHub Codespaces | Visual Studio Code Extension API

vchirikov commented 2 years ago

@JoeRobich could you take a look at this?

JoeRobich commented 2 years ago

@vchirikov When running a devcontainer the C# extension runs in the vscode-server process in the container. Will have to investigate why it is isWindows is not defined.