27

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?

Giorgos V
  • 291
  • 1
  • 3
  • 7
  • 1
    Same problem on linux ubuntu 21.10 --> OmniSharp server started with Mono 6.8.0. info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 0 MSBuild instance(s) Could not locate MSBuild . It was working until today. I didn't change anything. – Kunta Kinte Mar 26 '22 at 00:58
  • And same problem here, It is a message from today too. https://serveanswer.com/questions/c-vscode-error-could-not-locate-msbuild-instance-to-register-with-omnisharp – Kunta Kinte Mar 26 '22 at 01:13

16 Answers16

26

As of May 2022, Omnisharp does not include MSBuild.

It can be installed with Build Tools for Visual Studio, found at the bottom of this page.

During install select .NET desktop build tools:

enter image description here

More info in this issue.

chantey
  • 4,252
  • 1
  • 35
  • 40
  • 11
    Hey, Unity User which face IntelliSense problem after May 2022! This is what you need... (VS Community and Code) – ErTR Jun 06 '22 at 22:27
  • 1
    @ErTR exactly! Ran into this while trying to setup VS Code to work with Unity and this answer fixed it for me. – Moohasha Jun 28 '22 at 02:55
  • 2
    The site doesn't note this, but I think it's important: the Build Tools also work for VS Code. – Kyle Challis Aug 09 '22 at 00:16
11

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

Shawn Sean
  • 134
  • 3
  • 1
    Finally got this problem working. For me it needed .NETFramework (Developer Pack) v.4.7.1 without it I received another error. To download the .NETFramework (Developer Pack) v.4.7.1 [link](https://dotnet.microsoft.com/en-us/download/dotnet-framework/net47) and press the offline installer. Thank you all. – Giorgos V Mar 26 '22 at 12:12
7

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.

Veeper
  • 71
  • 1
  • 3
  • This worked for me - but I couldn't downgrade within the Visual Studio code - had to uninstall and then download the VSIX file from the internet and "install from vsix" within the IDE – Kibi Jul 21 '22 at 12:16
4

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

Koi Tri
  • 41
  • 1
  • Well... this works to me to. Although I am in unity 3D and this option says it not supports unity. But at for the moment I can compile for unity. I hope there are no other problems later. Thank you. – Kunta Kinte Mar 26 '22 at 02:32
  • Now I can compile but Unity autocompletion and contextual help are not working. – Kunta Kinte Mar 26 '22 at 02:39
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 26 '22 at 08:30
  • Working with Mono-based development (Unity) so this solution did not work for me. I was able to get things to work again by following the selected answer and also enabling useGlobalMono, i.e "omnisharp.path": "" and "omnisharp.useGlobalMono": "always" – Will Lacey May 27 '22 at 04:56
2

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.

1

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://learn.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.

Kunta Kinte
  • 351
  • 1
  • 2
  • 15
0

The solution that worked for me:

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

Paul Povel
  • 11
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 26 '22 at 12:26
0

For me runs with

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

on settings.json file....

0

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
Mani Gandham
  • 7,688
  • 1
  • 51
  • 60
  • I'm using Unity so have to set use useModernNet to false, and setting omnisharp.path to empty string did not solve the issue. – Marcos Pereira Jun 01 '22 at 17:08
  • @MarcosPereira How does Unity affect the Omnisharp build version? As long as you have the .net 6 SDK installed you can run the modern builds. – Mani Gandham Jun 02 '22 at 10:04
0

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

#5253 (comment)

General Grievance
  • 4,555
  • 31
  • 31
  • 45
M.Ubeyd
  • 61
  • 1
  • 6
0

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.

A.Keco
  • 1
  • 1
0

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.

0

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.

kr.one
  • 11
  • 1
0

Edit: For latest version

  1. Make sure you have Mono installed Link to Mono
  2. Make sure you have .Net sdk installed Link to .Net SDK
  3. Open VS Code
  4. Go into Settings
  5. Search and tick useOmnisharp
  6. Search and untick useModernNet
Madhav Arora
  • 61
  • 1
  • 4
0

Depending on your OS, you may have to install msbuild.

For arch linux you can do

sudo pacman -S mono-msbuild
Ragavendra
  • 90
  • 5
-1

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

CSharp
  • 1,573
  • 2
  • 14
  • 25