找不到框架“.NETFramework,Version=v4.7.1”的参考程序集

Reference assemblies for framework ".NETFramework,Version=v4.7.1" were not found

我尝试在 Linux (Ubuntu 18.10) 下用 VSCode 打开一个 Unity3D 项目。 omn​​isharp 扩展没有加载项目,说找不到程序集。

这可能看起来很愚蠢,但我还没有真正习惯 .Net,而且我已经被这个错误困扰了好几天。 我一直在尝试重新安装 dotnet(甚至使用 snap 包)、mono、vscode 和 omnisharp 扩展。

欢迎任何帮助! :)

统一版本:2018.3.1f1

日志:

dotnet -- 信息

.NET Core SDK (reflecting any global.json):
 Version:   2.2.103
 Commit:    8edbc2570a

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  18.10
 OS Platform: Linux
 RID:         ubuntu.18.10-x64
 Base Path:   /usr/share/dotnet/sdk/2.2.103/

Host (useful for support):
  Version: 2.2.1
  Commit:  878dd11e62

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

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

单声道--版本

Mono JIT compiler version 4.6.2 (Debian 4.6.2.7+dfsg-1ubuntu1)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug 
    LLVM:          supported, not enabled.
    GC:            sgen

完整日志错误:

    Starting OmniSharp server at 1/26/2019, 7:13:55 PM
    Target: /home/eyap/Projects/Unity/TestProject/TestProject.sln

OmniSharp server started.
    Path: /home/eyap/.vscode/extensions/ms-vscode.csharp-1.17.1/.omnisharp/1.32.8/run
    PID: 30136

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on ubuntu 18.10 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 15.0 - "/home/eyap/.vscode/extensions/ms-vscode.csharp-1.17.1/.omnisharp/1.32.8/omnisharp/msbuild/15.0/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to '/home/eyap/.vscode/extensions/ms-vscode.csharp-1.17.1/.omnisharp/1.32.8/omnisharp/msbuild/15.0/Bin/MSBuild.dll'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 15.0 - "/home/eyap/.vscode/extensions/ms-vscode.csharp-1.17.1/.omnisharp/1.32.8/omnisharp/msbuild/15.0/Bin"
            MSBuildExtensionsPath = /home/eyap/.vscode/extensions/ms-vscode.csharp-1.17.1/.omnisharp/1.32.8/omnisharp/msbuild
            BypassFrameworkInstallChecks = true
            CscToolPath = /home/eyap/.vscode/extensions/ms-vscode.csharp-1.17.1/.omnisharp/1.32.8/omnisharp/msbuild/15.0/Bin/Roslyn
            CscToolExe = csc.exe
            MSBuildToolsPath = /home/eyap/.vscode/extensions/ms-vscode.csharp-1.17.1/.omnisharp/1.32.8/omnisharp/msbuild/15.0/Bin
            TargetFrameworkRootPath = /usr/lib/mono/xbuild-frameworks
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/home/eyap/Projects/Unity/TestProject'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.WorkspaceInitializer
        Project system 'OmniSharp.DotNet.DotNetProjectSystem' is disabled in the configuration.
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/home/eyap/Projects/Unity/TestProject/TestProject.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/home/eyap/Projects/Unity/TestProject/Assembly-CSharp.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/home/eyap/Projects/Unity/TestProject'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/home/eyap/Projects/Unity/TestProject' on host 30056.
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /home/eyap/Projects/Unity/TestProject/Assembly-CSharp.csproj
[fail]: OmniSharp.MSBuild.ProjectLoader
        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.
[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file '/home/eyap/Projects/Unity/TestProject/Assembly-CSharp.csproj'.
/home/eyap/Projects/Unity/TestProject/Assembly-CSharp.csproj
/home/eyap/.vscode/extensions/ms-vscode.csharp-1.17.1/.omnisharp/1.32.8/omnisharp/msbuild/15.0/Bin/Microsoft.Common.CurrentVersion.targets(1195,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.

[fail]: OmniSharp.MSBuild.ProjectManager
        Attemped to update project that is not loaded: /home/eyap/Projects/Unity/TestProject/Assembly-CSharp.csproj

我在 OSX 上遇到了同样的问题。安装最新版本的 Mono 清除了丢失的 .net v4.7.1 框架引用。

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

安装了 Mono V5.18.0

更新:请参阅下面有关全局 omnisharp 设置的评论

我遇到了同样的情况,我在这里找到了解决方法:https://github.com/Microsoft/msbuild/issues/2728

您必须 export FrameworkPathOverride=/lib/mono/4.5 才能找到 .NETFramework。

  1. In linux mint 18.3 Sylvia (ubuntu 16.04) 安装 mono-devel like https://www.mono-project.com/download/stable/#download-lin.

  2. 然后在终端执行export FrameworkPathOverride=/etc/mono/4.5

  3. 打开 vs 代码并运行。

在 Linux mint 18.3 Sylvia (Ubuntu 16.04) 中安装 mono-devel,如 https://www.mono-project.com/download/stable/#download-lin。 然后在终端执行

export FrameworkPathOverride=/etc/mono/4.5

打开 VScode,它 works.This 对我来说对 Ubuntu 20.04.

的全新安装有用

我遇到了同样的问题,下面是我如何解决它的。

  1. here 下载最新的稳定 Mono 并安装。

  2. 将 FrameworkPathOverride 添加到 .bash_profile

export FrameworkPathOverride=/Library/Frameworks/Mono.framework/Versions/Current

重新启动 VSCode 即可。

尝试了这里提到的步骤,没有解决错误。必须将 omnisharp.useGlobalMono 选项更改为 always。这适用于 C# extension for VS Code=1.23.2.

来源:Reddit Post

Your error output tells me that you're using the official C# extension for VS Code. The latest version of said extension, 1.23.2, has this to say in its changelog:

For Mono-based development (e.g. Unity) that requires full .NET framework, you need to set "omnisharp.useGlobalMono": "always". This

is needed until Mono upgrades their bundled MSBuild version

The default setting, auto, does not work. Switch it to always and restart the extension. Alternatively you could downgrade to 1.23.1.

经过一天研究出了什么问题。在 ubuntu 上使用 .NETFRAMEWORK 4.7 和统一。我通过将 omnisharp:useglobalmenu 更改为 always inside VSCODE 设置解决了这个问题。这是一个解决方案 link 我找到了 https://github.com/OmniSharp/omnisharp-vscode/issues/3613#issuecomment-677451385

Windows 10 个用户:


如果您仍然遇到此 Omnisharp 错误:

The reference assemblies for .NETFramework,Version=v4.7.1 were not found.
  1. 如果 VS Code 已经打开,请关闭它

  2. 下载并安装 .NETFramework 4.7.1 开发包
    https://dotnet.microsoft.com/en-us/download/dotnet-framework/net471
    (VS Code 可能会建议较新的版本,但截至 2022 年 3 月 25 日,它们不起作用)

  3. 在 VS Code 中重新打开 Unity 项目


上述步骤应该可以解决问题,但如果您仍然遇到问题(例如,Intellisense 无法正常工作),请尝试调整您的 Unity 设置:

  1. 打开您的 Unity 项目,单击 编辑 > 项目设置... > 播放器 > 其他设置 > API 兼容级别(配置中)

  2. 将 API 兼容级别更改为 .NET 4.x

  3. 重启 Unity 和 VS Code