找不到“ GetReferenceNearestTargetFrameworkTask”任务

时间:2019-05-06 18:22:19

标签: visual-studio jenkins msbuild chocolatey

给出::我的本地系统在“ C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Professional \ MSBuild \ 15.0 \ Bin \ MSbuild.exe”中引用了MSBuild。我的自动构建服务器(Jenkins)没有此版本的MSBuild,因此我使用Chocolatey下载了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的引用程序集,版本= 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。但是,目标包4.6.2在路径“ C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework”中不存在。我认为它一次成功下载了该软件包,但是我删除了它以查看它在我的构建服务器(Jenkins)中是否可复制。

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

1 个答案:

答案 0 :(得分:0)

  

对于“ GetReferenceNearestTargetFrameworkTask”:

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

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

enter image description here

  

关于如何解决此参考装配问题的任何想法?

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,但现在坏了。

手动下载此developer pack并运行它可以帮助解决丢失的软件包。

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