我无法让 .net 框架在 vscode 中运行。当我正常打开vscode时,.net框架可以正常运行。但是,当我在 unity 中打开 .cs 文件并使用 vscode 作为默认编辑器时,我会收到错误消息,因为 .net 框架不再在 vscode 中运行。我需要 C# 特定自动完成和语法错误的框架。我收到了另一篇已关闭的帖子的评论,说我需要更具体地说明这个问题。这不是 Unity 不支持 .net 框架的问题。我尝试过重新启动电脑、重新启动 vscode、重新启动 unity、重新导入 unity 包以及重新下载 .net 框架。无论 vscode 是否使用 Unity 快捷方式启动,所有 C# 代码都可以在 Unity 内部和外部正常运行,但运行 dotnet 命令和任何与 C# 相关的自动完成/语法不起作用。我可以通过在没有 Unity 的情况下运行 vscode 并导航到该文件来从 Unity 编辑 C# 代码。感谢您的帮助。
在通过快捷方式启动的 vscode 中运行 dotnet 命令
Omnisharp 错误消息/日志:
Starting OmniSharp server at 5/30/2020, 9:41:51 PM Target: a:\Github\Unity\2_Terminal_Hacker\2_Terminal_Hacker.sln
OmniSharp server started. Path: c:\Users\0dps1.vscode\extensions\ms-dotnettools.csharp-1.22.0.omnisharp\1.35.2\OmniSharp.exe PID: 15076
[info]: OmniSharp.Stdio.Host Starting OmniSharp on Windows 6.2.9200.0 (x64) [info]: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 2 MSBuild instance(s) 1: Visual Studio Community 2019 16.6.30114.105 - "A:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin" 2: StandAlone 16.4 - "c:\Users\0dps1.vscode\extensions\ms-dotnettools.csharp-1.22.0.omnisharp\1.35.2.msbuild\Current\Bin" [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: Visual Studio Community 2019 16.6.30114.105 - "A:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin" [info]: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in 'a:\Github\Unity\2_Terminal_Hacker'. [info]: OmniSharp.Cake.CakeProjectSystem Could not find any Cake files [info]: OmniSharp.MSBuild.ProjectSystem Detecting projects in 'a:\Github\Unity\2_Terminal_Hacker\2_Terminal_Hacker.sln'. [info]: OmniSharp.MSBuild.ProjectManager Queue project update for 'a:\Github\Unity\2_Terminal_Hacker\Assembly-CSharp.csproj' [info]: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in 'a:\Github\Unity\2_Terminal_Hacker'. [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: a:\Github\Unity\2_Terminal_Hacker\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 'a:\Github\Unity\2_Terminal_Hacker' on host 13388. [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 'a:\Github\Unity\2_Terminal_Hacker\Assembly-CSharp.csproj'. a:\Github\Unity\2_Terminal_Hacker\Assembly-CSharp.csproj A:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1177,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: a:\Github\Unity\2_Terminal_Hacker\Assembly-CSharp.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 'a:\Github\Unity\2_Terminal_Hacker\Assembly-CSharp.csproj'. a:\Github\Unity\2_Terminal_Hacker\Assembly-CSharp.csproj A:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1177,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
.Net sdk/系统库是通过 Visual Studio 安装的,因此 vscode/omnisharp 尝试从 Visual Studio Community 16.6 安装中提取它们(相关信息位于日志的开头)。但 VSCommunity 似乎没有安装 v4.7.1 目标包。
要解决此问题,请访问:
Visual Studio Installer -> Visual Studio Community -> More -> Modify -> Individual Components
并检查“.NETFramework v4.7.1”包。安装完毕后,重新启动,就可以开始了。
关于c# - 通过 Unity 启动时,Visual Studio Code .NET 框架无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62111273/