首页 > 解决方案 > 未找到“GetReferenceNearestTargetFrameworkTask”任务

问题描述

鉴于:我的本地系统在“C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSbuild.exe”中引用了 MSBuild。我的自动构建服务器 (Jenkins) 没有这个版本的 MSBuild,所以我用巧克力来下载 microsoft-build-tools。

问题:我的 Visual Studio 项目在本地编译成功,但由于 ReferenceAssembly 错误,无法在我的自动构建服务器 (Jenkins) 上成功编译:

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1179,5):错误 MSB3644:框架的参考程序集“.NETFramework,Version=未找到 v4.6.2"。要解决此问题,请为此框架版本安装 SDK 或 Targeting Pack,或者将您的应用程序重新定位到已安装 SDK 或 Targeting Pack 的框架版本。请注意,程序集将从全局程序集缓存 (GAC) 中解析,并将用于代替引用程序集。因此,您的程序集可能无法正确定位于您想要的框架。

我在网上搜索并找到了一个可能的解决方案https://developercommunity.visualstudio.com/content/problem/137779/the-getreferencenearesttargetframeworktask-task-wa.html其中powershell脚本修改了Microsoft Build Tools安装程序:

Start-Process "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" -ArgumentList 'modify --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools" --quiet --add Microsoft.VisualStudio.Component.NuGet.BuildTools --add Microsoft.Net.Component.4.6.2.TargetingPack --norestart --force' -Wait -PassThru

我运行了脚本,我可以看到它修改了安装程序以选择指定的目标 4.6.2。但是,路径“C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework”中不存在目标包 4.6.2。我认为它一次成功下载了该软件包,但我将其删除以查看它是否可以在我的构建服务器(Jenkins)中重现。

我不想手动将 v4.6.2 目标包从本地系统粘贴到构建服务器。关于如何解决这个参考组装问题的任何想法?

标签: visual-studiojenkinsmsbuildchocolatey

解决方案


对于“GetReferenceNearestTargetFrameworkTask”:

你可以使用powershell调用installer.exe,安装你缺少的组件。

此外,您可以在服务器中启动 vs 安装程序并修改构建工具以安装以下软件包:

在此处输入图像描述

关于如何解决这个参考组装问题的任何想法?

If they are unchecked, check them and click modify button to install them by vs installer.exe.

And if they are checked, uncheck them and click modify to remove completely. After that, check them to reinstall the 4.6.2 framework.

更新:

经过我检查后,无法帮助解决程序集的修改。此Get Tools and Features选项只能用于安装新框架(未安装一次),但不能修复已安装但现在损坏的 4.6.2。

手动下载这个开发包并运行它可以帮助解决丢失的包。

另外:我删除了v4.6.2文件夹C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework并通过运行包修复将其取回。


推荐阅读