1

I'm on macOS Catalina running:

  • vscode 1.48.1
  • ms-dotnettools.csharp 1.23.1 (which is omnisharp underneath)
  • Visual Studio For Mac 8.7.3
  • Mono MDK 6.12.0.91

I have a project that targets .NET 4.6.1. I use vscode for this project. I also have another project that uses Visual Studio For Mac for Xamarin reasons. Unfortunately, it seems that the later versions of Visual Studio For Mac require at least Mono MDK 6.10.x. That version doesn't appear to support .NET 4.6.1. This means Omnisharp can't load the projects for vscode project. I've tried downgrading the Mono MDK without success for the vscode project. All my googling gets me to the download pages for the developer packs for Windows that have .NET framework 4.6.1, which are useless, or ways to force Omnisharp to see a 4.6.1 framework at some other path by setting an environment variable, FrameworkPathOverride, to the appropriate place, which doesn't exist on my system. At this point the only path I can see is to retarget my 4.6.1 application to a later framework but that will take forever. All I really need is a 4.6.1 framework for macOS. Halp?

EDIT: Yes, I know .NET is for Windows and Mono is for everything else. Mono provides compatibility with .NET versions and Omnisharp has handled this properly in the past. The problem only appeared after updating Visual Studio For Mac and the Mono MDK.

EDIT: Solved, see accepted answer for details

jsimon
  • 577
  • 6
  • 17
  • 1
    Only .NET Core is the goal of OmniSharp, so .NET Framework or Mono is not really in scope (so they might work and break). You can talk to the developers directly via https://github.com/OmniSharp/omnisharp-vscode/issues – Lex Li Aug 25 '20 at 15:16
  • @LexLi while there wasn't an open issue related to my problem, perusing the repo led me to a solution, which I'll post here as a reply. Thanks! – jsimon Aug 25 '20 at 15:44

4 Answers4

15

The issue seems to have stemmed from Omnisharp's decision to include mono internally. They default to that version of the compiler, which isn't geared for .NET Framework but dotnet core. There is a setting in vscode that forces Omnisharp to use the globally installed Mono instead. Setting that to "always" fixes this issue. Open vscode settings and search for "global mono". Set the "Omnisharp: Use Global Mono" setting to "always." Alternatively, open your settings.json file and add "omnisharp.useGlobalMono": "always".

jsimon
  • 577
  • 6
  • 17
2
  1. Check which version of mono you have using which mono (i.e. /Library/Frameworks/Mono.framework/Versions/Current/)
  2. In VSCode edit settings.json and add the line "omnisharp.monoPath": "/Library/Frameworks/Mono.framework/Versions/Current/"
  3. Still in settings.json, edit set "omnisharp.useGlobalMono": "always"
  4. press cmd+shift+p and select Developer: Reload Window
Claus
  • 5,662
  • 10
  • 77
  • 118
  • This is still valid and helped me just now, but it's important to add that it matters to which `settings.jsson` you will add that `"omnisharp.monoPath"` property. Maybe it has changed in time, now you can only set it up in global users settings: `~/Library/Application Support/Code/User/settings.json` – lukasz Mar 20 '22 at 18:59
1

In case someone still facing the issue because you looked for other sources in order to fix this issue.

  1. First of all follow the answer from @jsimon .
  2. I had accidentally added this setting "omnisharp.useModernNet": true which generally says for .NET 6: This version _does not_ support non-SDK-style .NET Framework projects, including Unity. When I removed this setting - all was fixed.
Oleg Novosad
  • 2,261
  • 1
  • 27
  • 28
0

I had the same issue. it was fixed by the @jsimon's steps. Thank you!

OS : macOS Monterey version 12.2 MacBook Pro M1 arm64

VsCode 1.64.0 (universal) dotnet --version 6.0.101

steps: 1. open the VSCode 2. Code -> Preferences -> Extensions 3. click on the (wheal) settings on C# for Visual Studio Code (powered by OmniSharp). and Extension Settings 4. find Edit in settings.json add "omnisharp.useGlobalMono": "always" to the end. you may need to add "," if you have other settings 5. save and close, and open VsCode project. 6. go back to the ominsharp settings 7. Omnisharp: Use Modern Net , select this to use .NET 6 (in my case) enjoy!

alwisr
  • 11
  • 1
  • 3
  • Glad it worked for you. You can also use a project specific setting if you need a non global setting by putting "omnisharp.useGlobalMono": "never" into settings.json in the project's .vscode folder – jsimon Feb 08 '22 at 15:39
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31014427) – Attersson Feb 11 '22 at 14:08