简体   繁体   中英

Visual Studio Code .NET framework not working when launched through unity

I am having trouble getting the .net framework to run inside vscode. I can get the .net framework running fine when I open vscode normally. However, when I open a.cs file in unity and use vscode as my default editor, I get error messages because the .net framework no longer works inside vscode. I need the framework for c# specific autocomplete and syntax errors. I have gotten comments on another post that has been closed saying I need to be more specific about this issue. This is not an issue with unity not supporting the .net framework. I have tried restarting my pc, restarting vscode, restarting unity, reimporting unity packages, and redownloading the .net framework. All c# code runs fine inside and outside of unity regardless of whether vscode was launched using the unity shortcut, but running the dotnet command and any c# related autocomplete/syntax do not work. I can edit c# code from unity by running vscode without unity and navigating to the file. Thanks for your help.

dotnet command run in vscode launched by unity dotnet 命令在统一启动的 vscode 中运行

dotnet command run in vscode launched via shortcut dotnet 命令在通过快捷方式启动的 vscode 中运行

c# code working inside of unity c#代码在unity内部工作

Omnisharp error message/log:

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

The answer is in the log:

[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/system libraries are installed through Visual Studio, so vscode/omnisharp tried to pull them from your Visual Studio Community 16.6 installation (info for that is on the start of the log). But it looks like VSCommunity is installed without v4.7.1 targetting pack.

To fix this, go to:

Visual Studio Installer -> Visual Studio Community -> More -> Modify -> Individual Components

and check ".NETFramework v4.7.1" pack. Afrer this gets installed, reboot stuff and you should be good to go.

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