0

I am trying to get vscode to enable c# code completion with unity, as this guide shows. I had a problem earlier that for some reason the .NET targeting pack was installed but the SDK was not, which someone was able to help me with. However, I am still getting errors that say the reference assemblies cannot be found. I have re-installed the developer pack, the .NET SDK and targeting pack, restarted my computer, and uninstalled/ reinstalled extensions. The logs say I might have to retarget the application but that is very vague and I cannot find any guides on how to do that. Thanks for your help.

EDIT: I have tried changing the target framework to 4.8, but omnisharp has the same error log with a different version that I also installed. Could this be a problem with having multiple drives?

.csproj target framework:

v4.7.1

Omnisharp error log:

Starting OmniSharp server at 5/31/2020, 7:56:50 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: 5544

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

2
  • 1
    Which .NET Framework you are tareting? Commented Jun 1, 2020 at 2:41
  • Its in the error log, but v4.7.1 Commented Jun 1, 2020 at 2:42

1 Answer 1

4

https://learn.microsoft.com/en-us/dotnet/standard/frameworks

If you open .csproj files you will see "TargetFramework" tag, and inside it, one of the possible values from the link. "Retarget" means changing "Target Framework" value from "net471" to, say, "net46".

Unfortunately, since this is Unity project, Unity likes to have full control of the content of the csproj files, and any changes you make will be only temporary. So you may retarget to something and make the error go away, but Unity will revert this to "net471" on its whim later.

Your options are:

  1. Fix .net sdk /vscode installation so you get the targetting pack. You may try to open the solution in VS community and maybe it will offer a fix from the UI

  2. Unity has an inbuilt dropdown in player settings to target net2 or something like that instead of net471, but thats a really ancient version of c#/net. It might have been completely deprecated recently.

  3. Do hacks to inject yourself in unity csproj generation so it always use some version you have (not recommended)

EDIT - yes, it's actually very possible it's multiple drive issue. I see from your logs that Visual Studio Community is installed on A:\drive. Reference assemblies are usually found in "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework". So it's very likely that where MSBuild.exe is looking for those and where the targetting pack is actually installed are mismatched.

Don't really have any idea how to fix this other than trying to install VS in default location on C:\ - probably there are some magic environment variables that can be set to trigger MSBuild to look in the right place.

Sign up to request clarification or add additional context in comments.

2 Comments

VS Commuinty doesn't offer any fix, but it works the way I would like VS Code to. I will try and edit the .csproj file now.
It didn't work with 4.8, and unity didn't change the version (yet). Could this be a problem with having multiple drives?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.