dotnet / vscode-csharp

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

Announcement: Planned removal of the included Mono & MSBuild tools #5120

Closed JoeRobich closed 1 week ago

JoeRobich commented 2 years ago

Background:

The included Mono and MSBuild tools were added to support easy development of C# using .NET Core. We have frequently updated these build tools to match the current shipping SDK tooling.

On Windows we did not need to ship a copy of Mono because we could rely on the .NET Framework being installed. For MacOS and Linux we shipped a minimal Mono that would support running MSBuild and OmniSharp. With these tools, the .NET SDK installed, and the dotnet CLI discoverable from the environment PATH, developers would have good support when developing against the newer SDK-style projects.

There was some support for Full Framework projects with this configuration, but that was considered a bonus. Our most common Full Framework projects (Unity) were unsupported with this configuration because the .NET 4.7.1 targeting pack was not included.

In the future .NET Framework OmniSharp builds will not ship with Mono or the MSBuild tooling (See announcement omnisharp-roslyn#2339, See PR omnisharp-roslyn#2360).

Proposal:

To ensure that the C# extension remains usable out of the box for .NET SDK projects, we will be changing the default value of omnisharp.useModernNet to true. This means by default OmniSharp will run on the .NET SDK and .NET Framework projects will likely not load properly. It will require the .NET 6 SDK be installed and the dotnet CLI to be discoverable from the environment PATH.

Users who need .NET Framework support will have to set omnisharp.useModernNet to false to download the .NET Framework build of OmniSharp. Linux and MacOS users will need to have a complete system install of Mono including MSBuild (Download). Windows users will need to have the Visual Studio MSBuild Tools or a full Visual Studio installed (Download).

Screenshot of the Visual Studio download page.

The omnisharp.useGlobalMono setting will be removed as there is no longer an included Mono and we will always use the system installation of Mono.

HaraldKorneliussen commented 2 years ago

I guess the removal of bundled msbuild is the reason omnisharp suddenly fails on my projects with

The MSBuild option 'UseBundledOnly' is no longer supported. Please update your OmniSharp configuration files.

Having a bundled version seems like a good idea to me, especially if the alternative is chasing version dependencies manually.

filipw commented 2 years ago

We never shipped .NET Framework reference assemblies, so the bundled MSBuild was only suitable for .NET Core (and .NET 5+) development, and it was a poor man's replacement for discovering the MSBuild from the .NET SDK installation.

Since for .NET Core (and .NET 5+) development you anyway need to have the relevant .NET SDK installed, and since .NET SDK has the appropriate MSBuild already, this will be the MSBuild discovered and used by OmniSharp.

NoTuxNoBux commented 2 years ago

Does this mean that using Unity projects with this package will essentially become impossible for the time being without changing the flag back (or after the flag is dropped)?

It just so happens that I already created an issue on the Unity VSCode package issue tracker around Unity generating legacy .NET Framework 4.7 csproj files instead of the newer format, even if the project is set to API compatibility .NET Standard 2.0. If I understand correctly, this is a change that Unity must make to keep its package compatible with OmniSharp on the long term?

JoeRobich commented 2 years ago

Does this mean that using Unity projects with this package will essentially become impossible for the time being without changing the flag back (or after the flag is dropped)?

Yes, for your unity projects you can set omnisharp.useModernNet to false in the Workspace settings instead of User settings. This should allow you to use the modern build of O# by default, but have it do the right thing in configured Unity workspaces.

If I understand correctly, this is a change that Unity must make to keep its package compatible with OmniSharp on the long term?

Yes, Unity could possibly continue to target net471, but they would definitely need to update to SDK-style projects.

tngmrk77 commented 2 years ago

Hi @JoeRobich, I set "omnisharp.useModernNet": false for User and Workspace but intellisense's omnisharp dont'works Can you help me please? :( I have version VSCode 1.66.2 and extension C# version 1.24.4

JoeRobich commented 2 years ago

@tngmrk77 Can you please open a new issue and provide the requested OmniSharp Log and C# Log from the VS Code output pane?

JoeRobich commented 2 years ago

These changes will be complete when v1.25.0 ships.

JoeRobich commented 2 years ago

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.

esklarski commented 2 years ago

This seems to have completely broken Unity projects.

If I set useModernNet to false as suggested I just get a different error: `

    DotNetPath set to /usr/lib64/dotnet/dotnet
    Located 0 MSBuild instance(s)

Could not locate MSBuild instance to register with OmniSharp. `

Or with useModernNet set true I get: /usr/lib64/dotnet/sdk/6.0.105/Microsoft.Common.CurrentVersion.targets(1217,5): Error: This project targets .NET version that requires reference assemblies that are not installed (e.g. .NET Framework). The most common solution is to make sure Mono is fully updated on your machine (https://mono-project.com/download/) and that you are running the .NET Framework build of OmniSharp (e.g. 'omnisharp.useModernNet': false in C# Extension for VS Code).

I'm on Fedora 36 and everything seems installed when I go through setup set again (and again).

wanieru commented 2 years ago

Having the exact same issue as @esklarski, I'm on Fedora 35.

JoeRobich commented 2 years ago

@esklarski From the error Could not locate MSBuild instance to register with OmniSharp., It does not appear that your system install of Mono includes MSBuild. Which mono packages do you have installed? Perhaps this page is helpful in getting a working dev environment -https://developer.fedoraproject.org/tech/languages/dotnet/mono.html

mrchantey commented 2 years ago

fyi I wrote a stackoverflow answer for how I got it working again on Windows.

liujinlong123 commented 2 years ago

Can you provide a solution on ubuntu ?

esklarski commented 2 years ago

@esklarski From the error Could not locate MSBuild instance to register with OmniSharp., It does not appear that your system install of Mono includes MSBuild. Which mono packages do you have installed? Perhaps this page is helpful in getting a working dev environment -https://developer.fedoraproject.org/tech/languages/dotnet/mono.html

I've done exactly as those instructions say.

dnf install mono-develop

I forget the exact version just now, 6 something.

The problem could be the Fedora packaging, any suggestion how to check?

[xxxx@fedora ~]$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.105
 Commit:    1c35735293

Runtime Environment:
 OS Name:     fedora
 OS Version:  36
 OS Platform: Linux
 RID:         fedora.36-x64
 Base Path:   /usr/lib64/dotnet/sdk/6.0.105/

Host (useful for support):
  Version: 6.0.5
  Commit:  70ae3df4a6

.NET SDKs installed:
  6.0.105 [/usr/lib64/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.5 [/usr/lib64/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.5 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
[xxxx@fedora ~]$ mono --version
Mono JIT compiler version 6.12.0.122 (tarball Thu Jan 20 20:34:53 UTC 2022)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug 
    Interpreter:   yes
    LLVM:          supported, not enabled.
    Suspend:       hybrid
    GC:            sgen (concurrent by default)
liujinlong123 commented 2 years ago

This is my steps:

  1. mono: sudo apt install mono-complete
    mk@mk:~$ mono --version
    Mono JIT compiler version 6.12.0.179 (tarball Tue May 17 21:33:45 UTC 2022)
    Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug 
    Interpreter:   yes
    LLVM:          yes(610)
    Suspend:       hybrid
    GC:            sgen (concurrent by default)
    mk@mk:~$
  2. .net sdk: ./dotnet-install.sh -c Current
    
    mk@mk:~$ dotnet --info
    .NET SDK (反映任何 global.json):
    Version:   6.0.300
    Commit:    8473146e7d

运行时环境: OS Name: ubuntu OS Version: 20.04 OS Platform: Linux RID: ubuntu.20.04-x64 Base Path: /home/mk/.dotnet/sdk/6.0.300/

Host (useful for support): Version: 6.0.5 Commit: 70ae3df4a6

.NET SDKs installed: 6.0.104 [/home/mk/.dotnet/sdk] 6.0.202 [/home/mk/.dotnet/sdk] 6.0.300 [/home/mk/.dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.4 [/home/mk/.dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.5 [/home/mk/.dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.4 [/home/mk/.dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.5 [/home/mk/.dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download mk@mk:~$


3. `Omnisharp` version is 1.25.0; `vscode` version is 1.67, settings.json
```json
"omnisharp.useModernNet": true,
  1. but it still doesn't work
    
    Starting OmniSharp server at 2022/5/26 10:19:05
    Target: /home/mk/workLiu/simulation/unity/L_Learn

OmniSharp server started with .NET 6.0.300 . Path: /home/mk/.vscode/extensions/ms-dotnettools.csharp-1.25.0-linux-x64/.omnisharp/1.39.0-net6.0/OmniSharp.dll PID: 46793

    Starting OmniSharp on Unknown 0.0 (Unknown)
    Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
    Using the 'dotnet' on the PATH.
    DotNetPath set to dotnet
    Located 3 MSBuild instance(s)
        1: .NET Core SDK 6.0.300 17.2.0 - "/home/mk/.dotnet/sdk/6.0.300/"
        2: .NET Core SDK 6.0.202 17.1.1 - "/home/mk/.dotnet/sdk/6.0.202/"
        3: .NET Core SDK 6.0.104 17.0.0 - "/home/mk/.dotnet/sdk/6.0.104/"
    Registered MSBuild instance: .NET Core SDK 6.0.300 17.2.0 - "/home/mk/.dotnet/sdk/6.0.300/"
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
    Detecting projects in '/home/mk/workLiu/simulation/unity/L_Learn/L_Learn.sln'.
    Queue project update for '/home/mk/workLiu/simulation/unity/L_Learn/Assembly-CSharp.csproj'
    Queue project update for '/home/mk/workLiu/simulation/unity/L_Learn/Assembly-CSharp-Editor.csproj'
    Detecting CSX files in '/home/mk/workLiu/simulation/unity/L_Learn'.
    Did not find any CSX files
    Configuration finished.
    Omnisharp server running using Stdio at location '/home/mk/workLiu/simulation/unity/L_Learn' on host 46614.
    Loading project: /home/mk/workLiu/simulation/unity/L_Learn/Assembly-CSharp.csproj
    This project targets .NET version that requires reference assemblies that are not installed (e.g. .NET Framework). The most common solution is to make sure Mono is fully updated on your machine (https://mono-project.com/download/) and that you are running the .NET Framework build of OmniSharp (e.g. 'omnisharp.useModernNet': false in C# Extension for VS Code).
    Failed to load project file '/home/mk/workLiu/simulation/unity/L_Learn/Assembly-CSharp.csproj'.

/home/mk/workLiu/simulation/unity/L_Learn/Assembly-CSharp.csproj /home/mk/.dotnet/sdk/6.0.300/Microsoft.Common.CurrentVersion.targets(1221,5): Error: This project targets .NET version that requires reference assemblies that are not installed (e.g. .NET Framework). The most common solution is to make sure Mono is fully updated on your machine (https://mono-project.com/download/) and that you are running the .NET Framework build of OmniSharp (e.g. 'omnisharp.useModernNet': false in C# Extension for VS Code).

    Loading project: /home/mk/workLiu/simulation/unity/L_Learn/Assembly-CSharp-Editor.csproj
    This project targets .NET version that requires reference assemblies that are not installed (e.g. .NET Framework). The most common solution is to make sure Mono is fully updated on your machine (https://mono-project.com/download/) and that you are running the .NET Framework build of OmniSharp (e.g. 'omnisharp.useModernNet': false in C# Extension for VS Code).
    Failed to load project file '/home/mk/workLiu/simulation/unity/L_Learn/Assembly-CSharp-Editor.csproj'.

/home/mk/workLiu/simulation/unity/L_Learn/Assembly-CSharp-Editor.csproj /home/mk/.dotnet/sdk/6.0.300/Microsoft.Common.CurrentVersion.targets(1221,5): Error: This project targets .NET version that requires reference assemblies that are not installed (e.g. .NET Framework). The most common solution is to make sure Mono is fully updated on your machine (https://mono-project.com/download/) and that you are running the .NET Framework build of OmniSharp (e.g. 'omnisharp.useModernNet': false in C# Extension for VS Code).

    Attempted to update project that is not loaded: /home/mk/workLiu/simulation/unity/L_Learn/Assembly-CSharp.csproj
    Attempted to update project that is not loaded: /home/mk/workLiu/simulation/unity/L_Learn/Assembly-CSharp-Editor.csproj
esklarski commented 2 years ago

I did some checking and as far as I can tell msbuild is installed properly on my system.

[xxxx@fedora ~]$ dotnet msbuild -ver
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

17.0.0.26101

Not sure why Omnisharp can't find it...

EDIT I got it to work by downgrading the extension to 1.24.4, and adding the following to the settings.json:

"omnisharp.useModernNet": false,
"omnisharp.path": "",
"omnisharp.useGlobalMono": "always",

From here upgrading to 1.25.0 breaks the MSBuild connection again. Seems 1.25.0 is the problem.

JoeRobich commented 2 years ago

@liujinlong123 If you are trying to do Unity development, then you need to set useModernNet to false

From the output you shared:

The most common solution is to make sure Mono is fully updated on your machine (https://mono-project.com/download/) and that you are running the .NET Framework build of OmniSharp (e.g. 'omnisharp.useModernNet': false in C# Extension for VS Code).

JoeRobich commented 2 years ago

@esklarski Can you try the mono-complete package?

I did some checking and as far as I can tell msbuild is installed properly on my system.

Mono does not use the dotnet SDK version of MSBuild.

esklarski commented 2 years ago

@esklarski Can you try the mono-complete package?

I did some checking and as far as I can tell msbuild is installed properly on my system.

Mono does not use the dotnet SDK version of MSBuild.

I have the mono-complete package installed, and v1.25.0 still breaks things.

JoeRobich commented 2 years ago

@esklarski Lets continue this investigation on https://github.com/OmniSharp/omnisharp-vscode/issues/5232. Hopefully we can come up with a workable solution.

liujinlong123 commented 2 years ago

@liujinlong123 If you are trying to do Unity development, then you need to set useModernNet to false

From the output you shared:

The most common solution is to make sure Mono is fully updated on your machine (https://mono-project.com/download/) and that you are running the .NET Framework build of OmniSharp (e.g. 'omnisharp.useModernNet': false in C# Extension for VS Code).

Thanks!!

DavidJVitale commented 2 years ago

I understand the need for breaking software changes like this, but please consider communicating this change in a more clear way to end-users. I have the latest mono installed, but OmniSharp server would completely silently fail and give no indication of what was wrong. Not every user of VS code would think to check this github page when that happens. Maybe a popup in vs-code linking to this announcement would be helpful?

For more details -- I am on Ubuntu, latest version of mono installed, using vs-code with mono. My OmniSharp server would fail to even start, show no output at all in VS code. No icon in the bottom tray. Ctrl + Shift + P -> Restart OmniSharp Server is the top google result, and that would silently fail. Running OmniSharp: Analyze Current Project would throw a OmniSharp server is not running error, but top google results send you in a wrong direction. Finally, I found this page, and going to Settings and setting UseModernNet to false fixed my error.

Thank you for all the work your team does!

kmcfate commented 2 years ago

To fix Intellisense/Omnisharp on Ubuntu 22.04 use https://launchpad.net/~eofla/+archive/ubuntu/msbuild and install the msbuild and msbuild-roslyn packages. Also make sure omnisharp.useModernNet is false and the mono-complete package is installed.

abreu9999 commented 2 years ago

To fix Intellisense/Omnisharp on Ubuntu 22.04 use https://launchpad.net/~eofla/+archive/ubuntu/msbuild and install the msbuild and msbuild-roslyn packages. Also make sure omnisharp.useModernNet is false and the mono-complete package is installed.

Thanks, this fixed the error "Could not locate MSBuild instance to register with OmniSharp" for me. Regards

1w1f commented 2 years ago

We never shipped .NET Framework reference assemblies, so the bundled MSBuild was only suitable for .NET Core (and .NET 5+) development, and it was a poor man's replacement for discovering the MSBuild from the .NET SDK installation.

Since for .NET Core (and .NET 5+) development you anyway need to have the relevant .NET SDK installed, and since .NET SDK has the appropriate MSBuild already, this will be the MSBuild discovered and used by OmniSharp.

if find many dotnet sdk ,how to select the sdk to find msbuild to Registered MSBuild instance?

JoeRobich commented 2 years ago

@1w1f You can set the omnisharp.sdkVersion to the version string you would like to load. You can also configure your omnisharp.json like so (see SDKOptions.cs).

{
  "SDK": {
    "Version": "{enter version string}"
  }
}
Hakazaba commented 1 year ago

To fix Intellisense/Omnisharp on Ubuntu 22.04 use https://launchpad.net/~eofla/+archive/ubuntu/msbuild and install the msbuild and msbuild-roslyn packages. Also make sure omnisharp.useModernNet is false and the mono-complete package is installed.

I'm getting a Broken pipe error when installing Msbuild-roslyn after Msbuild: Unpacking msbuild-roslyn (1:17.1-0ppa3) ... dpkg: error processing archive /var/cache/apt/archives/msbuild-roslyn_1%3a17.1-0ppa3_all.deb (--unpack): trying to overwrite '/usr/bin/csc', which is also in package mono-roslyn 6.12.0.182-0xamarin1+ubuntu1804b1 dpkg-deb: error: paste subprocess was killed by signal (Broken pipe) Errors were encountered while processing: /var/cache/apt/archives/msbuild-roslyn_1%3a17.1-0ppa3_all.deb E: Sub-process /usr/bin/dpkg returned an error code (1)

myocytebd commented 1 year ago

There is a minor bug that, after set useModernNet=false, omnisharp restarts and immediately fails due to lack of OmniSharp.exe.
It seems that .NET framework build don't download until restart vscode.
It is minor but confusing: omnisharp should instructs user to restart vscode.

ATikadze commented 1 year ago

Hello, I'm working in VS Code + Unity on macOS and until today everything was working fine. Today I opened vs code, disabled Use Modern Net (because sometimes I work on .Net 6) and it displays the following error (I'll attach the screenshot too): OmniSharp requires a complete install of Mono (including MSBuild) to provide language services when omnisharp.useModernNet is disabled in Settings. Please install the latest Mono and restart.

Screenshot 2022-11-09 at 4 23 41 PM

I downloaded Mono, even though I had a very recent version, and restarted vs code. It still shows this error. Keep in mind that yesterday it was working fine.

Software versions:

macOS Monterey 12.6 Unity 2021.3.11f1 VS Code 1.73.0 Mono 6.12.0

filipw commented 1 year ago

@ATikadze see https://github.com/OmniSharp/omnisharp-vscode/issues/5443#issuecomment-1308357445

ATikadze commented 1 year ago

@filipw Reverted C# extension to 1.25.0 and works again. Thanks 👍

alexandr-osprey commented 1 year ago

@filipw @ATikadze still have the same issue in 1.25.2 using dev container with mcr.microsoft.com/dotnet/sdk:5.0 mono installed like this

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

I can provide full repository with dockerfile if needed

crawlchange commented 1 year ago

"Go To Definition" is STILL not working on windows, vscode. What is this plugin good for? NOTHING in the documentation works. All the commands do NOTHING.