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

Created on 19 Jun 2018  路  24Comments  路  Source: OmniSharp/omnisharp-vscode

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!

Most helpful comment

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/

All 24 comments

Hi @jstrauss. Thanks for taking the time to write this up so nicely for us! I'm not really sure the best way to diagnose this further. I do remember that some of the other reporters of this issue were trying to target .NET 4.5--are you able to load a project that targets 4.5?

Also @jstrauss this bug (https://github.com/OmniSharp/omnisharp-vscode/issues/2381) reports that the version in homebrew doesn't contain the right dependencies. Maybe try installing it using the installer from mono directly?

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.

Note concerning my personal issue: I upgraded my Homebrew mono, and this bug went away and was replaced with #2386. My concerns about the quality of VS Code's error reporting in the case of a broken system mono remain. >_>

@mcclure I'm sorry you're having trouble configuring your environment. I also want to thank you for taking the time to file issues and raise concerns--that's the best way for us to identify improvements we can make. As you have observed, the configuration story is complex and could be better documented, especially for users not familiar with .NET. I suspect that we will make improvements in the form of both better documentation/FAQs in this github repo and as code changes that print more actionable errors. C# for VS Code is a composition of several different pieces of software and the configuration matrix is huge, but we should definitely improve our docs for certain common configurations.

To answer some of your specific questions:

Are you running /usr/local/bin/mono? Are you running /usr/local/share/dotnet/dotnet?

OmniSharp, the server used by the C# extension, always runs on mono. The option "omnisharp.useGlobalMono" controls whether we use the mono built into the extension, or mono from your path. We don't have any hardcoded mono paths apart from the built in one.

Do you have your own internal version of .NET you installed

Non-Windows builds of OmniSharp include mono framework assemblies and will use them at runtime if you opt to use the built-in mono. I don't think these assemblies can satisfy a request for a ".NET 4.x" SDK, however. Generally, errors about ".NET 4.x" SDKs mean you need to install mono. ".NET 4.6" is "desktop .NET", which is supported by mono for non-Windows machines.

I'd love to help you find a resolution to the problem you're still having. To make it easier to keep track of the discussion, would you mind filing a _new issue_ and including the following:

  • output of dotnet --info
  • output of mono --version
  • OmniSharp log from VS Code

Thanks!

OmniSharp, the server used by the C# extension, always runs on mono. The option "omnisharp.useGlobalMono" controls whether we use the mono built into the extension, or mono from your path. We don't have any hardcoded mono paths apart from the built in one.

This is useful to know. I am poking around the documentation and do not find this information in an obvious place. Perhaps that can be something that is addressed in the future improvements you mention.

I'd love to help you find a resolution to the problem you're still having. To make it easier to keep track of the discussion, would you mind filing a new issue and including the following:

Since my previous comment, I have replaced Homebrew mono with mono-project.com mono and the problem went away, so I can no longer reproduce. If I switch back to Homebrew at some point and am still seeing the issue, I will file a new bug. Thanks.

I'm in the same boat with this:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1122,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.

I've installed standalone dotnet core, mono, vs tools plugins, restarted my system etc... with no luck. Changed "useGlobalMono" to always, no luck still. Sort of stymied. I need to be able to use modern .net features, but can't get vs code/omni sharp to work with the project settings when I switch unity to 4.x.

Suggestions would be super appreciated!

C:\Users\clayt>dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.1.302
 Commit:    9048955601

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.302\

Host (useful for support):
  Version: 2.1.2
  Commit:  811c3ce6c0

.NET Core SDKs installed:
  2.1.302 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
C:\Users\clayt>mono --version
Mono JIT compiler version 5.12.0 (Visual Studio built mono)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           normal
        SIGSEGV:       normal
        Notification:  Thread + polling
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug
        Interpreter:   yes
        LLVM:          supported, not enabled.
        GC:            sgen (concurrent by default)

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

@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!

@claytongulick Glad you got it working!
@jstrauss Haven't heard from you in a while but we've identified a couple of solutions in this thread. I'm closing this issue, but feel free to keep commenting or open a new one.

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/

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

@rchande I have a similar issue, and have v4.7.1 in that location, however my error is coming from D:\Main\Program Files\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1179,5) is it possible the issue is some of my installs are on my D drive? If so how would I resolve this?

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.

I came across this on MAC with vscode (dotnet core CLI tool actually) and mono 5.12 when I tried to compile an application targeting .NET Framework 4.7.1. I checked and I clearly had the right assemblies in /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.7.1-api/.

$ mono --version
Mono JIT compiler version 5.12.0.309 (2018-02/39d89a335c8 Thu Sep 27 06:54:53 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-release_60/8b1520c8aae)
    GC:            sgen (concurrent by default)
$ dotnet build
Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restoring packages for ****.csproj...
  Generating MSBuild file ****.csproj.nuget.g.props.
  Restore completed in 256.36 ms for ****.csproj.
/usr/local/share/dotnet/sdk/2.1.302/Microsoft.Common.CurrentVersion.targets(1179,5): error MSB3644: 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. [****.csproj]

So clearly MSBuild failed to find those assemblies. Googling eventually yielded this comment on Github which solved my problem.

I noticed though that adding that the PropertyGroup (as suggested by that comment) would only work if it's listed after the TargetFramework declaration in the "csproj" file.

I fixed this issue on Mac simply by opening Visual Studio (not Code) and being prompted to download the latest SDK. I didn't have to open the project.

Perhaps this error could somehow be caught by OmniSharp and either suggest what to download (like VS does) or could give guidance to the user via a popup (rather than having to read through the "problems" tab)?

Cheers.

@rhys-vdw Can you share your mono --version and dotnet --version outputs?

@rchande

-> mono --version
Mono JIT compiler version 5.12.0.309 (2018-02/39d89a335c8 Thu Sep 27 06:54:53 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-release_60/8b1520c8aae)
    GC:            sgen (concurrent by default)
-> dotnet --version
2.1.302

I got the same error message when compiling with dotnet build under the following environment:

  • macOS 10.12.6
  • dotnet --version: 2.2.101
  • mono --version: Mono JIT compiler version 5.18.0.225 (tarball Thu Jan 10 03:11:06 GMT 2019)
  • Mono installed with Homebrew (/usr/local/bin/mono)

However, running msbuild in the solution folder works. I thought dotnet build was just a facade around msbuild, but according to https://github.com/Microsoft/msbuild/issues/1720#issuecomment-280691896, apparently not.

@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!

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.

@davidbyttow Sorry you are running into issues. Could you a new issue for the problem you are seeing and provide the requested logs so that we can investigate?

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

After all this, @davidbyttow 's answer was the simple fix that worked for me too. I've installed dotnet-sdk and mono via my package mananger (Add/Remove in Manjaro), though the versions are slightly different. 3.1.108 and 6.10.0 respectively. But I also have the default of .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.

Was this page helpful?
0 / 5 - 0 ratings