需要帮助重新定位.NET应用程序 [英] Need help retargeting .NET application

查看:151
本文介绍了需要帮助重新定位.NET应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取vscode以统一启用c#代码完成,例如指南显示.之前我有一个问题,由于某种原因,安装了.NET目标包,但没有安装SDK,有人可以帮我但是,我仍然收到错误消息,指出找不到参考程序集.我已经重新安装了开发人员包,.NET SDK和目标包,重新启动了计算机,并卸载/重新安装了扩展程序.日志显示我可能必须重新定位应用程序,但这非常含糊,我找不到任何有关该操作方法的指南.感谢您的帮助.

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.

我尝试将目标框架更改为4.8,但是omnisharp具有与我也安装的版本不同的相同错误日志.拥有多个驱动器可能会出问题吗?

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目标框架:

.csproj target framework:

v4.7.1

v4.7.1

Omnisharp错误日志:

Omnisharp error log:

在5/31/2020,7:56:50 PM启动OmniSharp服务器目标:a:\ Github \ Unity \ 2_Terminal_Hacker \ 2_Terminal_Hacker.sln

Starting OmniSharp server at 5/31/2020, 7:56:50 PM Target: a:\Github\Unity\2_Terminal_Hacker\2_Terminal_Hacker.sln

OmniSharp服务器已启动.路径:c:\ Users \ 0dps1.vscode \ extensions \ ms-dotnettools.csharp-1.22.0.omnisharp \ 1.35.2 \ OmniSharp.exePID:5544

OmniSharp server started. Path: c:\Users\0dps1.vscode\extensions\ms-dotnettools.csharp-1.22.0.omnisharp\1.35.2\OmniSharp.exe PID: 5544

[信息]:OmniSharp.Stdio.Host在Windows 6.2.9200.0(x64)上启动OmniSharp [信息]:OmniSharp.Services.DotNetCliServiceDotNetPath设置为dotnet [info]:OmniSharp.MSBuild.Discovery.MSBuildLocator找到了2个MSBuild实例1:Visual Studio Community 2019 16.6.30114.105-"A:\ Program Files \ Microsoft VisualStudio \ 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实例:Visual Studio社区2019 16.6.30114.105-"A:\ Program Files \ Microsoft Visual Studio \ 2019 \ Community \ MSBuild \ Current \ Bin" [信息]:OmniSharp.Cake.CakeProjectSystem在"a:\ Github \ Unity \ 2_Terminal_Hacker"中检测Cake文件.[信息]:OmniSharp.Cake.CakeProjectSystem找不到任何Cake文件[信息]:OmniSharp.MSBuild.ProjectSystem在"a:\ Github \ Unity \ 2_Terminal_Hacker \ 2_Terminal_Hacker.sln"中检测项目.[信息]:OmniSharp.MSBuild.ProjectManager排队项目更新"a:\ Github \ Unity \ 2_Terminal_Hacker \ Assembly-CSharp.csproj" [信息]:OmniSharp.Script.ScriptProjectSystem在'a:\ Github \ Unity \ 2_Terminal_Hacker'中检测CSX文件.[信息]:OmniSharp.Script.ScriptProjectSystem找不到任何CSX文件[信息]:OmniSharp.WorkspaceInitializer调用工作区选项提供程序:OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider,顺序:0 [信息]:OmniSharp.MSBuild.ProjectManager加载项目:a:\ Github \ Unity \ 2_Terminal_Hacker \ Assembly-CSharp.csproj [info]:OmniSharp.WorkspaceInitializer调用工作区选项提供程序:OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider,订单:100 [info]:OmniSharp.WorkspaceInitializer调用工作区选项提供程序:OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider,订单:110 [info]:OmniSharp.WorkspaceInitializer调用工作区选项提供程序:OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider,订单:140 [info]:OmniSharp.WorkspaceInitializer配置完成.[信息]:OmniSharp.Stdio.Host使用Stdio在主机4260上的位置'a:\ Github \ Unity \ 2_Terminal_Hacker'上运行的Omnisharp服务器.[失败]:OmniSharp.MSBuild.ProjectLoader找不到.NETFramework,Version = v4.7.1的参考程序集.要解决此问题,请安装Developer Pack(SDK/定位Pack)以适合此框架版本,或重新定位您的应用程序.你可以在以下位置下载.NET Framework开发人员包 https://aka.ms/msbuild/developerpacks [警告]:OmniSharp.MSBuild.ProjectManager无法加载项目文件'a:\ Github \ Unity \ 2_Terminal_Hacker \ Assembly-CSharp.csproj'.A:\ Github \ Unity \ 2_Terminal_Hacker \ Assembly-CSharp.csproj A:\ Program文件\ Microsoft VisualStudio \ 2019 \ Community \ MSBuild \ Current \ Bin \ Microsoft.Common.CurrentVersion.targets(1177,5):错误:.NETFramework,Version = v4.7.1的引用程序集是未找到.要解决此问题,请安装Developer Pack(SDK/定位Pack)以适合此框架版本,或重新定位您的应用程序.你可以在以下位置下载.NET Framework开发人员包 https://aka.ms/msbuild/developerpacks

[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

[失败]:OmniSharp.MSBuild.ProjectManager尝试更新未加载的项目:a:\ Github \ Unity \ 2_Terminal_Hacker \ Assembly-CSharp.csproj

[fail]: OmniSharp.MSBuild.ProjectManager Attempted to update project that is not loaded: a:\Github\Unity\2_Terminal_Hacker\Assembly-CSharp.csproj

推荐答案

https://docs.microsoft.com/zh-cn/dotnet/standard/frameworks

如果打开.csproj文件,您将看到"TargetFramework"标记,在其中,它是链接中可能的值之一.重新定位"意味着将目标框架"的值从"net471"更改为"net46".

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".

不幸的是,由于这是Unity项目,因此Unity希望完全控制csproj文件的内容,并且您所做的任何更改都只是暂时的.因此,您可以将目标重定向到某处并使错误消失,但是Unity稍后会一时兴起将其恢复为"net471".

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.

您的选择是:

  1. 修复.net sdk/vscode安装,以便获得目标包.您可以尝试在VS社区中打开该解决方案,也许它将通过UI提供修复程序

  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

Unity在播放器设置中有一个内置下拉列表,用于定位net2或类似的东西,而不是net471,但这是c#/net的真正古老版本.最近可能已完全弃用它.

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.

进行黑客攻击,将自己注入统一的csproj生成中,以便它始终使用您拥有的某个版本(不推荐)

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

编辑-是的,实际上很可能是多驱动器问题.我从您的日志中看到Visual Studio社区已安装在A:\ drive上.参考程序集通常可以在"C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework"中找到.因此,很有可能MSBuild.exe所寻找的位置与目标安装包的实际位置不匹配.

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.

除了尝试在C:\的默认位置安装VS之外,实际上没有任何其他方法可以解决此问题-可能有一些不可思议的环境变量可以设置为触发MSBuild在正确的位置显示.

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.

这篇关于需要帮助重新定位.NET应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆