简体   繁体   中英

VSCode Unity OmniSharp .NETFramework not found

I get this message in the output of 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.

this is what my dotnet output looks like

~ 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

With this error I can't get any IDE features for C# in VSCode.

You should have both .NET framework and targeting sdk installed for a particular version.

This is a temporary solution because targetFrameworkVersion always changes to unity defaults when you close the editor

Install latest stable Mono Version should fix the issue for this one, if anyone faces a similar issue.

Or try a different one until it is resolved, might be some mono versions preventing this.

The following worked for me (Unity 2022.3.3f1):

  • Install C# VS Code plugin
  • Download and install 4.7.1 Developer Pack (you will need to scroll past .NET Core to .NET Framework) (this version number may be different, but it will appear in the OUTPUT tab of VSCode as the version of C# you are using with unity.)
    • The file will look like ndp471-devpack-enu.exe
  • Download and install .NET sdk for Visual Studio (same download as this page ). This will add dotnet to your PATH and get VSCode to recognize it. Omnisharp/Intellisense did not work for me without this step.
    • The file will look like dotnet-sdk-6.0.300-win-x64.exe
  • In Unity, Go to Edit > Preferences > External Tools and ensure Visual Studio Code is the External Script Editor. Press Regenerate project files
  • Restart PC

You shouldn't need to change settings.json or anything else

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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