简体   繁体   English

需要帮助重定向 .NET 应用程序

[英]Need help retargeting .NET application

I am trying to get vscode to enable c# code completion with unity, as this guide shows.指南所示,我正在尝试让 vscode 以统一方式启用 c# 代码完成。 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.早些时候我遇到了一个问题,由于某种原因,安装了 .NET 目标包,但没有安装 SDK,有人能够帮助我解决这个问题。 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.我已经重新安装了开发包 .NET SDK 和目标包,重新启动了我的计算机,并卸载/重新安装了扩展。 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.编辑:我尝试将目标框架更改为 4.8,但是omnisharp 具有相同的错误日志,但我也安装了不同的版本。 Could this be a problem with having multiple drives?这可能是多个驱动器的问题吗?

.csproj target framework: .csproj 目标框架:

v4.7.1 v4.7.1

Omnisharp error log: Omnisharp 错误日志:

Starting OmniSharp server at 5/31/2020, 7:56:50 PM Target: a:\Github\Unity\2_Terminal_Hacker\2_Terminal_Hacker.sln在 2020 年 5 月 31 日晚上 7:56:50 启动 OmniSharp 服务器目标:a:\Github\Unity\2_Terminal_Hacker\2_Terminal_Hacker.sln

OmniSharp server started. OmniSharp 服务器已启动。 Path: c:\Users\0dps1.vscode\extensions\ms-dotnettools.csharp-1.22.0.omnisharp\1.35.2\OmniSharp.exe PID: 5544路径: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.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 社区 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" [信息]: OmniSharp.MSBuild.Discovery.MSBuildLocator 已注册 MSBuild 实例 "A:\Program Files 2019 16.6.3" Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin" [信息]:OmniSharp.Cake.CakeProjectSystem 检测 'a:\Github\Unity\2_Terminal_Hacker' 中的 Cake 文件。 [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'. [信息]:OmniSharp.Cake.CakeProjectSystem 找不到任何蛋糕文件 [信息]:OmniSharp.MSBuild.ProjectSystem 检测“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'. [信息]:OmniSharp.MSBuild.ProjectManager 'a:\Github\Unity\2_Terminal_Hacker\Assembly-CSharp.csproj' 的队列项目更新 [信息]:OmniSharp.Script.ScriptProjectSystem 检测 'a:\Github\Unity\ 中的 CSX 文件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. [信息]:OmniSharp.Script.ScriptProjectSystem 找不到任何 CSX 文件 [信息]:OmniSharp.WorkspaceInitializer 调用工作区选项提供程序:OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider,订单:0 [信息]:OmniSharp.MSBuild.ProjectManager 正在加载项目:a:\Github\Unity\2_Terminal_Hacker\Assembly-CSharp.csproj [信息]:OmniSharp.WorkspaceInitializer 调用工作区选项提供程序:OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider,订单:100 [信息]:OmniSharp.WorkspaceInitializer 调用工作区选项提供程序:OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider,订单:110 [信息]:OmniSharp.WorkspaceInitializer 调用工作区选项提供程序:OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider,订单:140 [信息]:OmniSharp.WorkspaceInitializer 配置完成. [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. [信息]:OmniSharp.Stdio.Host Omnisharp 服务器使用 Stdio 在主机 4260 上的位置“a:\Github\Unity\2_Terminal_Hacker”运行。[失败]:OmniSharp.MSBuild.ProjectLoader .NETFramework 的参考程序集,版本 = v4。 7.1 没有找到。 To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application.要解决此问题,请为此框架版本安装开发包(SDK/Targeting Pack)或重新定位您的应用程序。 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'. 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. 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):错误:The .NETFramework,Version=v4.7.1 的参考程序集未找到。 To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application.要解决此问题,请为此框架版本安装开发包(SDK/Targeting Pack)或重新定位您的应用程序。 You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks您可以在https://aka.ms/msbuild/developerpacks下载 .NET 框架开发人员包

[fail]: OmniSharp.MSBuild.ProjectManager Attempted to update project that is not loaded: a:\Github\Unity\2_Terminal_Hacker\Assembly-CSharp.csproj [失败]:OmniSharp.MSBuild.ProjectManager 尝试更新未加载的项目:a:\Github\Unity\2_Terminal_Hacker\Assembly-CSharp.csproj

https://docs.microsoft.com/en-us/dotnet/standard/frameworks https://docs.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.如果您打开 .csproj 文件,您将看到“TargetFramework”标签,并在其中看到来自链接的可能值之一。 "Retarget" means changing "Target Framework" value from "net471" to, say, "net46". “重新定位”意味着将“目标框架”值从“net471”更改为“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.不幸的是,由于这是 Unity 项目,Unity 喜欢完全控制 csproj 文件的内容,您所做的任何更改都只是暂时的。 So you may retarget to something and make the error go away, but Unity will revert this to "net471" on its whim later.因此,您可能会重新定位到某些东西并消除错误 go,但 Unity 稍后会随心所欲地将其恢复为“net471”。

Your options are:您的选择是:

  1. Fix .net sdk /vscode installation so you get the targetting pack.修复 .net sdk /vscode 安装,以便获得目标包。 You may try to open the solution in VS community and maybe it will offer a fix from the UI您可以尝试在 VS 社区中打开解决方案,也许它会从 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. Unity 在播放器设置中有一个内置的下拉菜单来定位 net2 或类似的东西,而不是 net471,但那是一个非常古老的 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)做一些技巧来将自己注入到统一的 csproj 生成中,所以它总是使用你拥有的某个版本(不推荐)

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.我从您的日志中看到 Visual Studio Community 安装在 A:\drive 上。 Reference assemblies are usually found in "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework".参考程序集通常位于“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.因此,MSBuild.exe 查找这些文件的位置与实际安装目标包的位置很可能不匹配。

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.除了尝试在 C:\ 上的默认位置安装 VS 之外,真的不知道如何解决此问题 - 可能有一些神奇的环境变量可以设置为触发 MSBuild 以查看正确的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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