vscode-csharp: Unable to load .NET 4.6 project in VS Code / Mac even with mono-mdk and stable mono installed

Environment data

dotnet --info output:

.NET Command Line Tools (2.1.4)

Product Information:
 Version:            2.1.4
 Commit SHA-1 hash:  5e8add2190

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.12
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.1.4/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.5
  Build    : 17373eb129b3b05aa18ece963f8795d65ef8ea54

VS Code version: 1.24.1 C# Extension version: 1.15.2

Steps to reproduce

  1. Ensure mono and/or mono-mdk is installed
  2. Open project that targets .NET Framework 4.6 in VS Code on macOS
  3. Observe OmniSharp Log window

Expected behavior

Solution and its projects should load properly, and OmniSharp server should initialize successfully.

Actual behavior

OmniSharp is unable to load the project in question and fails. The specific error is one that I have seen referenced in a few other issues on this repo:

[fail]: OmniSharp.MSBuild.ProjectLoader
        The reference assemblies for framework ".NETFramework,Version=v4.6" were not found. To resolve
        this, install the SDK or Targeting Pack for this framework version or retarget your
        application to a version of the framework for which you have the SDK or Targeting Pack
        installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will
        be used in place of reference assemblies. Therefore your assembly may not be correctly
        targeted for the framework you intend.

I have seen where certain versions of the mono formula were causing problems, and also have seen the suggestion to install the mono-mdk cask instead. So far, I have uninstalled the mono formula entirely. As for the MDK:

$ brew cask info mono-mdk

mono-mdk: 5.12.0.226
http://www.mono-project.com/
/usr/local/Caskroom/mono-mdk/5.12.0.226 (346.3MB)
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/mono-mdk.rb
==> Name
Mono
==> Artifacts
MonoFramework-MDK-5.12.0.226.macos10.xamarin.universal.pkg (Pkg)
==> Caveats
Installing mono-mdk removes mono and mono dependant formula binaries in
/usr/local/bin and adds mono-mdk to /private/etc/paths.d/
You may want to:

  brew unlink {formula} && brew link {formula}

and/or remove /private/etc/paths.d/mono-commands

I’ve also reinstalled the latest stable Mono Framework for MacOS using the downloadable package available directly from www.mono-project.com.

$ mono --version

Mono JIT compiler version 5.12.0.226 (2018-02/9824e260f56 Mon Apr 30 18:45:52 EDT 2018)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	Interpreter:   yes
	LLVM:          yes(3.6.0svn-mono-master/8b1520c8aae)
	GC:            sgen (concurrent by default)

Please accept my apologies if this particular iteration of the issue has already reported and resolved elsewhere. I spoke briefly offline with @DustinCampbell about it, and he suggesting posting the issue here and CC’ing @rchande.

Let me know if there additional info needed. Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 25 (2 by maintainers)

Most upvoted comments

Just a quick note here to confirm updating mono indeed fix this issue for macOS.

I had mono 5.8.0 and Unity 2018.2 and ran into the same error when trying to start omnisharp on VSCode:

The reference assemblies for framework “.NETFramework,Version=v4.7.1” were not found`

It’s easily fixed by updating to latest mono (5.12 at the moment)

https://www.mono-project.com/download/stable/

I am encountering much this same issue. I managed to hit this by creating a Unity 2018.2.0b9 project, using VS Code as my code editor, upgrading the Unity project to their “.NET 4.x equivalent” scripting runtime version and “.NET 4.x” API compatibility level, setting up an MSBuild build task in VS Code, and then running the build task. The exact error I get, in the Output pane, is

[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file '/Users/mcc/work/u/SRProject2/Assembly-CSharp.csproj'.
/Users/mcc/work/u/SRProject2/Assembly-CSharp.csproj
/Users/mcc/.vscode/extensions/ms-vscode.csharp-1.15.2/.omnisharp/1.30.1/omnisharp/msbuild/15.0/Bin/Microsoft.Common.CurrentVersion.targets(1140,5): Error: The reference assemblies for framework ".NETFramework,Version=v4.7.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.

Following this, building does not seem to “do anything” (it does not notice when I ask it to compile a file with syntax errors).

I would like to stress a separate issue from the mere fact this is not working. The problem as I see it is VS Code / omnisharp does not provide information sufficient to debug this problem on my own. I do not know how to install an “SDK or targeting pack”. I could look this up, but I do not know what .NET installation VS Code is using. Are you running /usr/local/bin/mono? Are you running /usr/local/share/dotnet/dotnet? (I have both mono and the CLR installed locally.) Do you have your own internal version of .NET you installed (you apparently have an internal version of MSBuild, I see its path in the error message)? My expected behavior is that if I need to install something for Omnisharp to function, that VS Code would present a clear error message, instead of a stray message in “output”, and tell me what program I need to install additions to. This problem (inadequate error message in the case of messed up dependencies) is still a problem even if the issue with Homebrew @rchande mentions is fixed and it resolves this particular error.

@claytongulick Do you have a non-empty C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.1 folder on your machine? If not you need to use the Visual Studio Installer to install the 4.7.1 SDK. Because you are using Windows, you should be able to get this working without installing mono.

FWIW, on latest version of Unity (2020.1), I had the Intellisense problem too and resolved by adding "omnisharp.useGlobalMono": "always" to my settings.json

Meanwhile, my versions:

$ dotnet --version
3.1.401

$ mono --version
Mono JIT compiler version 6.8.0.123 (2019-10/1d0d939dc30 Thu Mar 12 23:19:08 EDT 2020)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           
        SIGSEGV:       altstack
        Notification:  kqueue
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug 
        Interpreter:   yes
        LLVM:          yes(610)
        Suspend:       hybrid
        GC:            sgen (concurrent by default)

And my API Compatibility Level is .NET Standard 2.0 in Unity Player settings.

I followed all of the instructions here. I also needed to add the following to my settings.json:

    "omnisharp.useGlobalMono": "always"

The instructions on the C# extension says that you should set this to never but I was unable to get it to work with the version installed with the extension.

@JoeRobich sorry if I wasn’t clear. I’m good now, but I don’t know if this was an omnisharp issue or just a local setup issue. Nevertheless, my symptoms were the same as this issue and I didn’t see a very clear resolution in the thread – so I decided to add my solution for the next person who might stumble upon this thread as I did.

@rchande you just barely beat me to it, I was about to come back here and post the solution.

Yep, I opened the solution in Visual Studio, and it helpfully prompted me to go here: https://www.microsoft.com/net/download/visual-studio-sdks to download the 4.7.1 development pack.

After doing that, all the problems disappeared. Thanks!

@rchande you just barely beat me to it, I was about to come back here and post the solution.

Yep, I opened the solution in Visual Studio, and it helpfully prompted me to go here: https://www.microsoft.com/net/download/visual-studio-sdks to download the 4.7.1 development pack.

After doing that, all the problems disappeared. Thanks!

Check if you can run “mono” on terminal. $ mono --version

Check if you have mono installed at following location. /Library/Frameworks/Mono.framework/Versions/Current/Commands/mono

if not, download and install mono from: https://www.mono-project.com/download/stable/

now on terminal do: $ brew update $ brew cask install mono $ brew link --overwrite mono

mono should work and so does the Omni in visual studio.