简体   繁体   中英

MacOS/VisualStudioCode/Omnisharp missing .NET Framework 4.6.1

I'm on macOS Catalina running:

  • vscode 1.48.1
  • ms-do.nettools.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

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" .

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.
  1. Check which version of mono you have using which mono (ie /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

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) do.net --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!

You can't.

The .NET Framework is exclusive to Microsoft Windows.

Visual Studio for Mac is for .NET Core, .NET Standard, Xamarin, and Mono.

The only way to build and work on .NET Framework projects on a Mac is to use Bootcamp or use a VM.

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