Could not locate MSBuild instance to register with OmniSharp

Viewed 12606

I have found many questions about this but non have helped me. I am trying to write c# code and the omnisharp auto complete doesn't work and I get this back from the Omnisharp Log:

OmniSharp server started.
    Path: c:\Users\GeorgV.216\.vscode\extensions\ms-dotnettools.csharp-1.24.1\.omnisharp\1.38.3-beta.31\OmniSharp.exe
    PID: 11536

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on Windows 6.2.9200.0 (x64)
[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 0 MSBuild instance(s)
Could not locate MSBuild instance to register with OmniSharp.

What could be a possible solution?

11 Answers

As of May 2022, Omnisharp does not include MSBuild. Download link can be found at the bottom of this page. In the install select the following option:

enter image description here

More info in this issue.

The solution that worked for me was to change the "omnisharp.path": from "latest" to "" in the setting.json file and delete the 1.38.3-beta.31 folder in C:\Users{username}.vscode\extensions\ms-dotnettools.csharp-1.24.1.omnisharp

If you're using VSCode, a simple fix is to install an older C# extension version.

Extensions -> arrow next to uninstall -> install another version -> v1.24.1

It's a temporary fix as you're stuck with an old version of C# extension but it's a quick and simple one.

Suddenly got this problem too, adding "omnisharp.useModernNet": true to the settings.json fixed it for me.

Working for me now. Maybe the cause is (from omnisharp github): "Planned removal of the included Mono & MSBuild Tools

In the future .NET Framework builds of OmniSharp will not ship with Mono or the MSBuild tooling (See announcement omnisharp-roslyn#2339). 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."

But " omnisharp.useModernNet to true" does not work with Unity 3d.

So.

I uninstall all dotnets from ubuntu. Unistall mono. Reinstall dotnet using this: https://docs.microsoft.com/es-es/dotnet/core/install/linux-ubuntu#2110- Reinstall mono-complete using synaptics. And in VS settings set omnisharp using global mono to "always". Now it's working for me.

The solution that worked for me:

Manage Settings search for "omnisharp path" edit in settings.json enter code here> replace "latest" with ""

For me runs with

"omnisharp.enableEditorConfigSupport": true,
"omnisharp.path": "latest",
"omnisharp.projectLoadTimeout": 60,
"omnisharp.useGlobalMono": "always",
"omnisharp.useModernNet": true,

on settings.json file....

Omnisharp has been updated to .NET 6.0. The older .NET Framework builds will no longer ship with MSBuild tools (and you don't already have them installed) so that's the reason for your error.

Remove the msbuild error by setting the following in VSCode settings.json:

"omnisharp.path": ""

Upgrade to the newer .NET 6.0 builds of OmniSharp by setting the following:

"omnisharp.useModernNet": true

Quick Solution for every platform (Windows, Linux, Mac)

  • Set VS Code update mode to 'manual'
  • Disable Windows Background Updates
  • Downgrade the VS Code version to February 2022 (version 1.65)
  • Downgrade the C# extension version to v1.24.4

everything will be fine

#5253 (comment)

Related