microsoft / vscode-dev-containers

NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!
https://aka.ms/vscode-remote
MIT License
4.71k stars 1.41k forks source link

How to fix OmniSharp broken in dotnet 3.1 image #1474

Open jkeech opened 2 years ago

jkeech commented 2 years ago

Steps to Reproduce:

  1. Create a codespace from https://github.com/microsoft/vscode-remote-try-dotnetcore
  2. Open Program.cs after the C# extension is installed (the extension might require a reload to fully activate)
  3. See this error in the output:
    
    Starting OmniSharp server at 5/25/2022, 6:57:38 PM
    Target: /workspaces/vscode-remote-try-dotnetcore

[ERROR] Error: Found dotnet version 3.1.419. Minimum required version is 6.0.100.


4. 🐛 OmniSharp doesn't load, and IntelliSense is broken

### Notes

This appears to be due to a breaking change in the latest OmniSharp release which will require compensating changes in either the image or the template: https://github.com/OmniSharp/omnisharp-vscode/issues/5120#issuecomment-1136335405

>v1.25.0 has shipped with this change. A .NET 6 SDK is required when running with "omnisharp.useModernNet" set to "true", which is the default configuration.

Either we should include a newer .NET 6 SDK on all versions of the .NET devcontainer images in order to allow OmniSharp to work, or we should add a setting for .NET versions <6 to set `"omnisharp.useModernNet": false` to workaround.
bamurtaugh commented 2 years ago

Either we should include a newer .NET 6 SDK on all versions of the .NET devcontainer images in order to allow OmniSharp to work, or we should add a setting for .NET versions <6 to set "omnisharp.useModernNet": false to workaround.

Either makes sense to me. We'd probably want to update the images themselves longer-term (option 1), in case folks are accessing them directly beyond this template?

gcamou commented 2 years ago

Any idea how I can fix temporarily meanwhile waiting for the fix it?

sergiocyklpoint commented 2 years ago

Root-cause:

After the release of OmniSharp v1.25.0, the extension no longer ships with an included Mono & MSBuild tools. This means you need the tools in your local machine to run the extension.

There are two fixes:

[Option 1] A workaround by downgrading the OmniSharp extension version, which I do not recommend!

[Option 2] Setup omnisharp.useModernNet setting to false and:

I've tested both solutions and both worked. Again I highly recommend the second one.

gcamou commented 2 years ago

Hello everyone. I fixed it, but it's temporary.

in the vscode setting I turn off useModernNet like @jkeech mentioned in the main comment and I need to download mono in my computer, and set MonoPath/Library/Frameworks/Mono.framework/Versions/Current/

CTNOriginals commented 2 years ago

@gcamou This indeed did it for me too! I'm so happy this thread has been created about this problem because I started having issues with this problem yesterday and could not explain why the f*** this happened now.... Thanks a lot guys!

VoItaik commented 2 years ago

@sergiocyklpoint tysm the second solution worked for me!

andreujuanc commented 2 years ago

Same here.

Installing a previous extension version does not work either => "Not compatible with my current version of vscode". Gonna have to install mono :/ MONO? Looks like C# is a second class citizen in vscode :/

Managed to get it to work

I use devContainers and this is my dockerfile

ARG VARIANT="3.1"
FROM mcr.microsoft.com/vscode/devcontainers/dotnet:${VARIANT}

RUN groupadd docker
RUN usermod -aG docker vscode

# This fixes dotnet test breaking tty
RUN touch ~/.bashrc
RUN echo ' \n\
dotnet () \n\
{ \n\
    local RET_VAL; \n\
    local BEFORE=$(stty -g); \n\
    $(which dotnet) "$@"; \n\
    RET_VAL=$?; \n\
    sleep 0.33; \n\
    stty "${BEFORE}"; \n\
    return $RET_VAL \n\
} ' >> /home/vscode/.bashrc

# This fixes omnisharp 
RUN apt-get install gnupg ca-certificates
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
RUN echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" | tee /etc/apt/sources.list.d/mono-official-stable.list
RUN apt-get update -y
RUN apt-get install mono-devel -y

Plus this setting: "omnisharp.useModernNet": false

bamurtaugh commented 2 years ago

Updated the title of this issue so that it's reflected as the issue users can review for workarounds if they encounter this. Please see the comments above (https://github.com/microsoft/vscode-dev-containers/issues/1474#issuecomment-1138768231) for how to address this.