本文介绍了通过单个命令通过 Nuget 安装多个包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 Visual Studio 的包管理器控制台使用 Nuget.对于每个项目,我需要添加几个包,例如xunit.contribs、fluentassertions 和 nsubstitute.为此,我在控制台中输入了 3 个命令.

I am using Nuget via Visual Studio's Package Manager Console. For every project I need to add few packages e.g. xunit.contribs, fluentassertions and nsubstitute. To do that I type 3 commands in consolle.

我知道控制台只是另一个 powershell 主机,应该有一种方法可以创建一个脚本(一种 Add-Test-Stuff.ps1),可以一次添加多个包.最好的方法是什么?

I understand that console is just another powershell host and there should be a way to create a script (kind of Add-Test-Stuff.ps1) that will add several packages at once. What is the best way to do that?

推荐答案

我通常在数组中定义我的包并使用 foreach 循环执行它们

I typically define my packages in arrays and execute them using a foreach loop

$angular = "AngularJS.Animate", "AngularJS.Core", "AngularJS.Locale", "AngularJS.Resource", "AngularJS.Route", "AngularJS.Sanitize", "AngularJS.Touch"
$angular | foreach {Install-Package $_}

这也可以写成单行

"AngularJS.Animate", "AngularJS.Core", "AngularJS.Locale", "AngularJS.Resource", "AngularJS.Route", "AngularJS.Sanitize", "AngularJS.Touch" | foreach {Install-Package $_}

这篇关于通过单个命令通过 Nuget 安装多个包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:10