通过命令行在 VS Installer 中启用 NuGet 包管理器。 (作为自动化脚本的一部分)

Posted

技术标签:

【中文标题】通过命令行在 VS Installer 中启用 NuGet 包管理器。 (作为自动化脚本的一部分)【英文标题】:Enable NuGet package manager in VS Installer through command line. (as part of automated script) 【发布时间】:2020-02-04 16:38:52 【问题描述】:

我想通过命令行启用 NuGet 包管理器,但我不知道该怎么做。

我们有一个安装 MSBuild15 BuildTools(使用 choco 命令)的 Jenkins 管道,我需要启用 NuGet 包管理器作为自动化脚本的一部分。

如果我直接在服务器/代理上启用它,则解决方案的编译成功,但我需要自动执行此步骤。

我已经附上了一张通过 vs_installer 的图片 -> Image of VS Installer, what i need to enable through command line

【问题讨论】:

您确定这是“启用” NuGet,而不是简单地将 nuget.exe 添加到您的 PATH 覆盖的目录中吗?您可以在此处找到 NuGet 可执行文件(不是安装程序,而是完整的可执行文件):nuget.org/downloads 尝试将其中一个放入 PATH 环境变量所涵盖的文件夹中。 @JoeCullinan 当我们不启用 NuGet 时,解决方案的“清理”失败并出现以下错误; CoreClean:创建目录“obj\Release\”。 C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1657,5):错误 MSB4036:找不到“GetReferenceNearestTargetFrameworkTask”任务。 i> 根据这个文档,答案是启用“NuGet 包管理器”link 在我完成此操作后,清理和构建工作。 @JoeCullinan 我想通过命令行自动启用这个功能。 【参考方案1】:

这应该在 Powershell 中工作:

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

在这里找到:https://developercommunity.visualstudio.com/content/problem/137779/the-getreferencenearesttargetframeworktask-task-wa.html#reply-160786

【讨论】:

谢谢,我已经在 PowerShell 模块中进行了测试,效果很好,干杯! 备用安装程序路径:C:\Program Files (x86)\Microsoft Visual Studio\installer\vs_installer.exe

以上是关于通过命令行在 VS Installer 中启用 NuGet 包管理器。 (作为自动化脚本的一部分)的主要内容,如果未能解决你的问题,请参考以下文章

通过命令行在 Git 提交消息中使用感叹号

通过命令行在 Visual Studio 中编译单个独立文件

如何通过命令行在pytest中传递参数

通过命令行在 Docker 中更改 --commit CMD 时出错

通过命令行在 Jboss 7.0.1 中部署战争

如何通过命令行在 MSBuild 中指定 CodeAnalysisRuleset