vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

Assemblies targeting .Net Framework 4.7.1 fail to load on Mac, plugin v1.21.11

Open edwardrowe opened this issue 6 years ago • 21 comments

Issue Description

When loading my Unity (v2018.4.2f) project in Visual Studio Code, the assemblies fail to load and intellisense doesn't work. This seems to have been introduced in version 1.21.11, as rolling back to v1.21.10 works fine.

Steps to Reproduce

  1. Create a project in Unity, v2018.4.2
  2. Target .Net Framework 4.7.1 by setting Scripting Runtime Version to .Net 4.x Equivalent in Edit/Project Settings/Player/Scripting Runtime Version image
  3. Open up the project in Visual Studio Code
  4. Observe the plugin fails to load the assemblies

Expected Behavior

The assemblies should load, allowing me to see function references and Go To implementations and definitions.

Actual Behavior

Intellisense and image

Logs

OmniSharp log

Starting OmniSharp server at 2/27/2020, 3:58:25 PM Target: /Users/erowe/Development/sparklite/sparklite.sln

OmniSharp server started. Path: /Users/erowe/.vscode/extensions/ms-vscode.csharp-1.21.11/.omnisharp/1.34.11/run PID: 26956

Starting OmniSharp on MacOS 10.14.6 (x64) info: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet info: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 1 MSBuild instance(s) 1: StandAlone 16.3 - "/Users/erowe/.vscode/extensions/ms-vscode.csharp-1.21.11/.omnisharp/1.34.11/omnisharp/.msbuild/Current/Bin" info: OmniSharp.MSBuild.Discovery.MSBuildLocator MSBUILD_EXE_PATH environment variable set to '/Users/erowe/.vscode/extensions/ms-vscode.csharp-1.21.11/.omnisharp/1.34.11/omnisharp/.msbuild/Current/Bin/MSBuild.dll' info: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: StandAlone 16.3 - "/Users/erowe/.vscode/extensions/ms-vscode.csharp-1.21.11/.omnisharp/1.34.11/omnisharp/.msbuild/Current/Bin" CscToolExe = csc.exe MSBuildToolsPath = /Users/erowe/.vscode/extensions/ms-vscode.csharp-1.21.11/.omnisharp/1.34.11/omnisharp/.msbuild/Current/Bin CscToolPath = /Users/erowe/.vscode/extensions/ms-vscode.csharp-1.21.11/.omnisharp/1.34.11/omnisharp/.msbuild/Current/Bin/Roslyn BypassFrameworkInstallChecks = true MSBuildExtensionsPath = /Users/erowe/.vscode/extensions/ms-vscode.csharp-1.21.11/.omnisharp/1.34.11/omnisharp/.msbuild info: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in '/Users/erowe/Development/sparklite'. info: OmniSharp.Cake.CakeProjectSystem Could not find any Cake files info: OmniSharp.MSBuild.ProjectSystem Detecting projects in '/Users/erowe/Development/sparklite/sparklite.sln'. info: OmniSharp.MSBuild.ProjectManager Queue project update for '/Users/erowe/Development/sparklite/Assembly-CSharp.csproj' info: OmniSharp.MSBuild.ProjectManager Queue project update for '/Users/erowe/Development/sparklite/Assembly-CSharp-firstpass.csproj' info: OmniSharp.MSBuild.ProjectManager Queue project update for '/Users/erowe/Development/sparklite/Assembly-CSharp-Editor.csproj' info: OmniSharp.MSBuild.ProjectManager Queue project update for '/Users/erowe/Development/sparklite/Assembly-CSharp-Editor-firstpass.csproj' info: OmniSharp.MSBuild.ProjectManager Queue project update for '/Users/erowe/Development/sparklite/RBG.Mulligan.csproj' info: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in '/Users/erowe/Development/sparklite'. info: OmniSharp.MSBuild.ProjectManager Loading project: /Users/erowe/Development/sparklite/Assembly-CSharp.csproj info: OmniSharp.Script.ScriptProjectSystem Could not find any CSX files info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100 info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110 info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.EditorConfigWorkspaceOptionsProvider, Order: 200 info: OmniSharp.WorkspaceInitializer Configuration finished. info: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location '/Users/erowe/Development/sparklite' on host 26922. fail: OmniSharp.MSBuild.ProjectLoader The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [warn]: OmniSharp.MSBuild.ProjectManager Failed to load project file '/Users/erowe/Development/sparklite/Assembly-CSharp.csproj'. /Users/erowe/Development/sparklite/Assembly-CSharp.csproj /Users/erowe/.vscode/extensions/ms-vscode.csharp-1.21.11/.omnisharp/1.34.11/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1193,5): Error: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

Loading project: /Users/erowe/Development/sparklite/Assembly-CSharp-firstpass.csproj fail: OmniSharp.MSBuild.ProjectLoader The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [warn]: OmniSharp.MSBuild.ProjectManager Failed to load project file '/Users/erowe/Development/sparklite/Assembly-CSharp-firstpass.csproj'. /Users/erowe/Development/sparklite/Assembly-CSharp-firstpass.csproj /Users/erowe/.vscode/extensions/ms-vscode.csharp-1.21.11/.omnisharp/1.34.11/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1193,5): Error: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

Loading project: /Users/erowe/Development/sparklite/Assembly-CSharp-Editor.csproj fail: OmniSharp.MSBuild.ProjectLoader The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [warn]: OmniSharp.MSBuild.ProjectManager Failed to load project file '/Users/erowe/Development/sparklite/Assembly-CSharp-Editor.csproj'. /Users/erowe/Development/sparklite/Assembly-CSharp-Editor.csproj /Users/erowe/.vscode/extensions/ms-vscode.csharp-1.21.11/.omnisharp/1.34.11/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1193,5): Error: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

Loading project: /Users/erowe/Development/sparklite/Assembly-CSharp-Editor-firstpass.csproj fail: OmniSharp.MSBuild.ProjectLoader The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [warn]: OmniSharp.MSBuild.ProjectManager Failed to load project file '/Users/erowe/Development/sparklite/Assembly-CSharp-Editor-firstpass.csproj'. /Users/erowe/Development/sparklite/Assembly-CSharp-Editor-firstpass.csproj /Users/erowe/.vscode/extensions/ms-vscode.csharp-1.21.11/.omnisharp/1.34.11/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1193,5): Error: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

Loading project: /Users/erowe/Development/sparklite/RBG.Mulligan.csproj fail: OmniSharp.MSBuild.ProjectLoader The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [warn]: OmniSharp.MSBuild.ProjectManager Failed to load project file '/Users/erowe/Development/sparklite/RBG.Mulligan.csproj'. /Users/erowe/Development/sparklite/RBG.Mulligan.csproj /Users/erowe/.vscode/extensions/ms-vscode.csharp-1.21.11/.omnisharp/1.34.11/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1193,5): Error: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

Attempted to update project that is not loaded: /Users/erowe/Development/sparklite/Assembly-CSharp.csproj fail: OmniSharp.MSBuild.ProjectManager Attempted to update project that is not loaded: /Users/erowe/Development/sparklite/Assembly-CSharp-firstpass.csproj fail: OmniSharp.MSBuild.ProjectManager Attempted to update project that is not loaded: /Users/erowe/Development/sparklite/Assembly-CSharp-Editor.csproj fail: OmniSharp.MSBuild.ProjectManager Attempted to update project that is not loaded: /Users/erowe/Development/sparklite/Assembly-CSharp-Editor-firstpass.csproj fail: OmniSharp.MSBuild.ProjectManager Attempted to update project that is not loaded: /Users/erowe/Development/sparklite/RBG.Mulligan.csproj

C# log

Installing C# dependencies... Platform: darwin, x86_64

Downloading package 'OmniSharp for OSX' (46346 KB).................... Done! Validating download... Integrity Check succeeded. Installing package 'OmniSharp for OSX'

Downloading package '.NET Core Debugger (macOS / x64)' (41849 KB).................... Done! Validating download... Integrity Check succeeded. Installing package '.NET Core Debugger (macOS / x64)'

Downloading package 'Razor Language Server (macOS / x64)' (50424 KB).................... Done! Installing package 'Razor Language Server (macOS / x64)'

Finished

Environment information

VSCode version: 1.42.1 C# Extension: 1.21.11

Mono Information OmniSharp using built-in mono
Dotnet Information .NET Core SDK (reflecting any global.json): Version: 2.1.401 Commit: 91b1c13032

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

Host (useful for support): Version: 2.1.3 Commit: 124038c13e

.NET Core SDKs installed: 2.1.401 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

Visual Studio Code Extensions
Extension Author Version
csharp ms-vscode 1.21.11
docomment k--kato 0.1.8
gitlens eamodio 10.2.1
rainbow-csv mechatroner 1.5.0
theme-dracula dracula-theme 2.20.0
unity-debug Unity 2.7.2
vscode-emacs hiro-sun 0.1.1

edwardrowe avatar Feb 27 '20 21:02 edwardrowe

@edwardrowe The built-in mono does not contain reference assemblies. To fix this problem you should install the stable mono - https://www.mono-project.com/download/stable/#download-mac

JoeRobich avatar Feb 27 '20 21:02 JoeRobich

This worked. Thanks so much for the help and quick feedback.

edwardrowe avatar Mar 02 '20 14:03 edwardrowe

To fix this problem you should install the stable mono

I did, but it didn't help. How should I reference installed Mono, so Unity can find missing Net Framerowrk?

DTX-92 avatar Jun 11 '20 12:06 DTX-92

@DTX-92 Can you share the omnisharp log from the Output pane?

JoeRobich avatar Jun 11 '20 17:06 JoeRobich

I was able to fix a problem by modifying my ~/.bash_profile to contain export FrameworkPathOverride thx

DTX-92 avatar Jun 14 '20 18:06 DTX-92

In my case, I have reinstalled the previous version of omnisharp plugin then it worked

image image

Another way to fix the issue without downgrade omnisharp plugin is to update the latest mono (https://www.mono-project.com/download/stable/). Set Use Global Mono to always image

giangchau92 avatar Aug 20 '20 08:08 giangchau92

you don't need to revert - see https://github.com/OmniSharp/omnisharp-vscode/issues/4007#issuecomment-677405332

filipw avatar Aug 20 '20 08:08 filipw

In my case, I have reinstalled the previous version of omnisharp plugin then it worked

image image

it's ok

snmimi avatar Aug 20 '20 10:08 snmimi

For anyone who can't find the Use Global Mono setting, go to Extension Settings at the bottom of the cog on the C# extension image

russellinho avatar Aug 23 '20 19:08 russellinho

giangchau92 Mine god man! Thank you..

image

So summary I did: Error: The reference assemblies for .NETFramework,Version=v4.7.1 Unity 2019.4.9f1 Macos

Downgrade to c# extension v1.23.0 as described above

Removed all csproj and regenerated it

  • Go to Unity -> Edit -> Preferences -> External Tools
  • Look for the section near the top called "Generate .csproj files for:" and click "Regenerate Project Files" with everything unchecked.
  • Then in VSCode I press "Cmd + Shift + P" and run the action for "Developer: Reload Window"

egorovsa avatar Sep 04 '20 05:09 egorovsa

Unity 2020.1.9f1 Personal, MacOS Catalina 10.15.7 (19H2) and the problem persists on versions >1.23.0 :/

hypeofpipe avatar Nov 06 '20 22:11 hypeofpipe

@hypeofpipe Sorry you are running into issues. The minimal Mono shipped with the C# extension does not contain 4.7.1 reference assemblies. Install the latest stable Mono 6.12.0 from https://www.mono-project.com/download/stable/ and set the omnisharp.useGlobalMono setting to "always". Also, ensure you are using the 1.2.3 VSCode Editor package in Unity.

JoeRobich avatar Nov 06 '20 22:11 JoeRobich

@giangchau92 's solution worked for me. Using homebrew I installed dotnet-sdk and mono, then I installed the C# extension in VSCode and had the error in the thread's title. The plugin was at version 1.23.5, I installed version 1.23.4 and now I get no errors in the OmniSharp's log and intellisense works.

Omnisharp.log at start:

Starting OmniSharp server at 11/11/2020, 11:28:49 AM
    Target: /Users/r/Projects/MessingWithEvents/MessingWithEvents.sln

OmniSharp server started with Mono 6.12.0.
    Path: /Users/r/.vscode/extensions/ms-dotnettools.csharp-1.23.4/.omnisharp/1.37.3/omnisharp/OmniSharp.exe
    PID: 14509

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on MacOS 10.15.7 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Mono 16.8.0 - "/usr/local/Cellar/mono/6.12.0.90/lib/mono/msbuild/Current/bin"
            2: StandAlone 16.8.0 - "/Users/r/.vscode/extensions/ms-dotnettools.csharp-1.23.4/.omnisharp/1.37.3/omnisharp/.msbuild/Current/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Mono 16.8.0 - "/usr/local/Cellar/mono/6.12.0.90/lib/mono/msbuild/Current/bin"
            CscToolExe = csc.exe
            CscToolPath = /Users/r/.vscode/extensions/ms-dotnettools.csharp-1.23.4/.omnisharp/1.37.3/omnisharp/.msbuild/Current/Bin/Roslyn
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/Users/r/Projects/MessingWithEvents'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/Users/r/Projects/MessingWithEvents/MessingWithEvents.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/r/Projects/MessingWithEvents/Assembly-CSharp.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/Users/r/Projects/MessingWithEvents'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/r/Projects/MessingWithEvents/Assembly-CSharp.csproj
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/Users/r/Projects/MessingWithEvents' on host 14487.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/r/Projects/MessingWithEvents/Assembly-CSharp.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/r/Projects/MessingWithEvents/Assembly-CSharp.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Assembly-CSharp

rstecca avatar Nov 11 '20 11:11 rstecca

@hypeofpipe Sorry you are running into issues. The minimal Mono shipped with the C# extension does not contain 4.7.1 reference assemblies. Install the latest stable Mono 6.12.0 from https://www.mono-project.com/download/stable/ and set the omnisharp.useGlobalMono setting to "always". Also, ensure you are using the 1.2.3 VSCode Editor package in Unity.

Thank you!! I am using Unity 2019.4.14f1 on MacOS Catalina 10.15.7, and I noticed the package for "VSCode Editor" was on older version 1.2.2. Upgrading to 1.2.3 fixed it.

OmniSharp' debug message is also not terribly helpful because AFAIK there is no .Net Framework 4.7.1 built for Mac. So what would help me debug this issue is knowing what are the responsible parties for this framework version determination. Is it Unity? Is it VSCode Editor? Is it maybe a solution misconfiguration with a default resolving to 4.7.1?

I know OmniSharp package isn't directly in charge of these other projects, and it's important to maintain some idempotency between them. However the reality is 99.9% of users encountering this major error are coming from a Unity on Mac environment. Some from Unity on Linux too. Therefore, some awareness of how Unity interoperates with OmniSharp and VSCode would all be very much more helpful. Maybe even provide a URL tip to a OmniSharp wiki page with up-to-date information on this common issue.

Also, Unity needs to do some sanity checking for developer work environments. Something really smart for Mac developers that checks and suggests what are working configurations.

otri avatar Nov 18 '20 03:11 otri

In my case, I have reinstalled the previous version of omnisharp plugin then it worked

image image

Another way to fix the issue without downgrade omnisharp plugin is to update the latest mono (https://www.mono-project.com/download/stable/). Set Use Global Mono to always image

Man.. i want to hug you! I've been fighting 3 days with it and just changed to use mono always. IT'S WORKING

Revolunk avatar Nov 18 '20 15:11 Revolunk

That "Global Mono to always" setting in VS Code was the thing I missed on the first try. Just installing the latest mono alone didn't do it. Thanks @giangchau92 !

matschaffer avatar Nov 21 '20 06:11 matschaffer

This does not work if you install the .Net Runtimes 5.x. Basically now this omnisharp no longer performs syntax checking on C# files, and now way to fix.

steowens avatar Dec 27 '20 21:12 steowens

@steowens OmniSharp's built-in Mono supports .NET 5.0, however the global Mono doesn't (there is no official Mono release that ships with MSBuild 16.8 which is required for .NET 5.0). We are waiting already several months for the relevant official Mono release https://github.com/mono/mono/issues/20250

filipw avatar Dec 28 '20 06:12 filipw

@hypeofpipe Sorry you are running into issues. The minimal Mono shipped with the C# extension does not contain 4.7.1 reference assemblies. Install the latest stable Mono 6.12.0 from https://www.mono-project.com/download/stable/ and set the omnisharp.useGlobalMono setting to "always". Also, ensure you are using the 1.2.3 VSCode Editor package in Unity.

At first I couldn't find this setting in vscode - it is not in Workspace settings but only in the User tab. Works like a charm though!

squio avatar Mar 14 '21 14:03 squio

In my case, I have reinstalled the previous version of omnisharp plugin then it worked

image image

Another way to fix the issue without downgrade omnisharp plugin is to update the latest mono (https://www.mono-project.com/download/stable/). Set Use Global Mono to always image

I've tried many stuff. Changing to always this config worked for me ! Thanks! Now I can see Intellisense in VS from Unity C# files! (Linux mint 19.3)

alejodeiuliis avatar Mar 27 '21 23:03 alejodeiuliis