繁体   English   中英

VSCode Unity OmniSharp .NETFramework 未找到

[英]VSCode Unity OmniSharp .NETFramework not found

我在 VSCode 的输出中收到此消息

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

这就是我的dotnet输出的样子

~ dotnet --info                                    
.NET Core SDK (reflecting any global.json):
 Version:   2.2.106
 Commit:    aa79b139a8

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

Host (useful for support):
  Version: 2.2.4
  Commit:  f95848e524

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

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

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

由于此错误,我无法在 VSCode 中获得 C# 的任何 IDE 功能。

您应该为特定版本安装 .NET 框架和目标 sdk。

这是一个临时解决方案,因为当您关闭编辑器时, targetFrameworkVersion总是更改为统一默认值

如果有人遇到类似问题,安装最新的稳定 Mono 版本应该可以解决这个问题。

或者在解决之前尝试不同的版本,可能是一些单声道版本阻止了这种情况。

以下对我有用(Unity 2022.3.3f1):

  • 安装 C# VS Code 插件
  • 下载并安装4.7.1 开发包(您需要从 .NET Core 滚动到 .NET Framework)(此版本号可能不同,但它将作为您使用的 C# 版本出现在 VSCode 的OUTPUT选项卡中统一。)
    • 该文件看起来像ndp471-devpack-enu.exe
  • 下载并安装Visual Studio 的 .NET sdk (与此页面相同的下载)。 这会将dotnet添加到您的 PATH 并让 VSCode 识别它。 如果没有这一步,Omnisharp/Intellisense 对我不起作用。
    • 该文件看起来像dotnet-sdk-6.0.300-win-x64.exe
  • 在 Unity 中,转到编辑 > 首选项 > 外部工具并确保Visual Studio Code是外部脚本编辑器。 Regenerate project files
  • 重启电脑

您不需要更改settings.json或其他任何内容

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM