简体   繁体   中英

Could not locate MSBuild instance to register with OmniSharp

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?

对我有用的解决方案是将 setting.json 文件中的“omnisharp.path”:从“latest”更改为“”,并删除 C:\Users{username}.vscode 中的 1.38.3-beta.31 文件夹\extensions\ms-dotnettools.csharp-1.24.1.omnisharp

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:

在此处输入图像描述

More info in this issue .

突然也遇到了这个问题,将 "omnisharp.useModernNet": true 添加到 settings.json 为我修复了它。

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.

将您的 Omnisharp 恢复到以前的版本,我的情况是从 1.25 到 1.24 VS Code C# 扩展

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)

Faced with same problem after upgrade to .net 6. In vs code problems with onmnisharp, intelisense and getting this error as well. Make sure to install mono latest version. Make sure to install .net 6.0.401 sdk.

If upgrade from .net 5 to .net 6 I suggest to uninstall first .net 5.

  1. Uninstall C# extension from vs code.
  2. Delete "ms-dotnettools.csharp-1.25.0-darwin-arm64" folder from /Users//.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64
  3. Install C# extension (1.25.0).
  4. Restart Vs code and got to Code>Preferences>Settings
  5. Search for "omnisharp"
  6. Set Logging Level to: trace
  7. Update Dotnet Path (on mac m1): "/usr/local/share/dotnet/dotnet"
  8. Update Mono path: (mac m1): "/Library/Frameworks/Mono.framework/Versions/Current"
  9. Update Sdk Path: "/usr/local/share/dotnet/sdk/6.0.401/"
  10. Update Sdk Version: "6.0.401"
  11. Set User Modern Net: true,
  12. Restart vs code -> check output console.
  13. If you get an error "The .NET Core SDK cannot be located. .NET Core debugging will not be enabled. Make sure the .NET Core SDK is installed and is on the path" continue line 14.
  14. Open "/Users/user/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/dist/extension.js" this file, and search for this statement: "args.push( Sdk:Path='${options.sdkPath}' );" than remove quotes around curly braces => args.push( Sdk:Path=${options.sdkPath} );.
  15. Save all changes and restart vs code. => Now everything should be ok.

Seems that this VsCode extension add quotes, and cause of this its not able to find "sdkPath" specified in the configuration.

This worked for me.

Hope will help someone.

Try installing the older version of C# extension works for me. I downgraded to v1.24.4 and changing one of the line in the setting.json to "omnisharp.useGlobalMono": "always"

I have also noticed that you have to close VS Code completely and reopen to have it working.

I spent at least an hour or two troubleshooting this issue and it seems there are several solutions which work for some but not for others. If you are like me and couldn't find a working solution, this is how I finally got it to work.

I disabled all of my other extensions in VS Code aside from 'C# for VS code' and 'Unity Code Snippets'. I'm not sure which one was the culprit, but I had been using VS Code mainly for JavaScript and I assume the code formatter or live server extensions were interfering somehow with how the.cs was being interpreted. All of a sudden after disabling those, and reloading, it worked. Finally.

If you're using VS Code, a temporary fix is to install an older C# extension version.

Extensions -> install another version -> v1.24.1

it will help as it helped for me.

Here is text from release note for Omnisharp v1.25.0: " Announcement: The C# extension no longer ships with an included Mono & MSBuild Tools ". I have installed .Net 6.0 and omnisharp v1.25.0 was able to locate MSBuild from there.

The older version of Omnisharp has MSBuild available within their extension install folder C:\Users\Username.vscode\extensions\ms-dotnettools.csharp-XX.XX.XX....omnisharp\X.XX.XX\msbuild

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM