问题:

问题:

我最近将操作系统从 Windows 切换到了 Ubuntu 20.04。在安装 Unity3D 时遇到一些问题后,我尝试安装 Visual Studio Code 进行 Unity 编码。

问题:

在 Unity3D 中按“打开 C# 项目”启动 Visual Studio Code 时,我收到一条错误消息(末尾有完整的错误消息):

[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

之后我可以编辑代码,但 Unity 的 IntelliSense(也许还有一些我还没有注意到的东西)不起作用

我已尝试过:

  • 安装 .NETFramework 版本 4.7.1:我不知道为什么,但是 4.X 版本不适用于 Linux。因此这不是一个选项。
  • 修改Assembly-CSharp.csproj文件:当将 更改TargetFrameworkVersion为我当前安装的 SDK 版本 (3.1.401) 或 Framework 版本 (3.1.7) 时,我会收到相同的错误消息。修改其他标签也无济于事。此外,每次 Unity 启动 Visual Studio Code 时,文件都会被重置。
  • 重新启动、重新安装 Visual Studio、重新安装 Unity、重置 Ubuntu
  • 按照其他论坛的建议安装 Mono。我真的不知道 mono 是什么或者它起什么作用,所以也许我在这里做错了什么……

有用的方法:

  • 使用 创建 C# Hello World 项目dotnet new Console。此项目可以通过 Visual Studio Code 打开、编译和运行,不会出现任何问题。如果需要,我可以提供此项目的一些文件。

  • 跑步单声道测试。

  • Unity 确实编译了代码并且完全正常运行。

可能有趣的东西:

我如何安装应用程序:

  • Unity:我使用从官方网站下载的 Appimage 文件
  • .Net:我关注了教程
  • Visual Studio Code:通过 Ubuntu 软件
  • Mono:我已关注这些脚步

.Net 安装

 Version:   3.1.401
 Commit:    39d17847db

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

Host (useful for support):
  Version: 3.1.7
  Commit:  fcfdef8d6b

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

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

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

Mono 安装

Mono JIT compiler version 6.10.0.104 (tarball Fri Jun 26 19:38:44 UTC 2020)
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 
    Interpreter:   yes
    LLVM:          yes(610)
    Suspend:       hybrid
    GC:            sgen (concurrent by default)

完整错误消息

Starting OmniSharp server at 8/28/2020, 10:20:28 AM
    Target: /home/jonas/Documents/Unity/testproject/testproject.sln

OmniSharp server started.
    Path: /home/jonas/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/run
    PID: 9757

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on ubuntu 20.4 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 16.8.0 - "/home/jonas/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild/Current/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to '/home/jonas/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 16.8.0 - "/home/jonas/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild/Current/Bin"
            CscToolExe = csc.exe
            MSBuildToolsPath = /home/jonas/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild/Current/Bin
            CscToolPath = /home/jonas/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild/Current/Bin/Roslyn
            BypassFrameworkInstallChecks = true
            MSBuildExtensionsPath = /home/jonas/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/home/jonas/Documents/Unity/testproject'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/home/jonas/Documents/Unity/testproject/testproject.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/home/jonas/Documents/Unity/testproject/Assembly-CSharp.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/home/jonas/Documents/Unity/testproject'.
[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: /home/jonas/Documents/Unity/testproject/Assembly-CSharp.csproj
[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 '/home/jonas/Documents/Unity/testproject' on host 9670.
[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 '/home/jonas/Documents/Unity/testproject/Assembly-CSharp.csproj'.
/home/jonas/Documents/Unity/testproject/Assembly-CSharp.csproj
/home/jonas/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1178,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

[fail]: OmniSharp.MSBuild.ProjectManager
        Attempted to update project that is not loaded: /home/jonas/Documents/Unity/testproject/Assembly-CSharp.csproj

由于我对 Ubuntu 和 Linux 还很陌生,我可能无意中遗漏了重要信息。请询问,我很乐意分享任何其他信息。感谢您的帮助

答案1

这对我有用。

https://github.com/OmniSharp/omnisharp-vscode/issues/3351

我认为这里的主要问题是 C# 扩展正在更新。但它与 VSCode 使用的 Mono 版本不兼容。

答案2

我遇到了同样的问题。但是从这里安装 .NET Framework 4.71 (https://dotnet.microsoft.com/en-us/download/visual-studio-sdks?cid=msbuild-developerpacks) 解决了这个问题。

答案3

我与 Jonas 的设置相同,并收到完全相同的错误消息,我没有从 @ardaboluk 提供的链接安装旧版本的 C# 扩展,而是转到 VS 代码的扩展选项卡,单击 C# 扩展降级了版本。您可以通过单击卸载按钮下拉菜单,然后单击“安装另一个版本...”来进行降级。我选择了版本 v1.21.18,它对我来说有效。

相关内容