.net 更新解决方案中所有项目中的 nuget 包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23477332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Updating nuget packages in all projects in a solution
提问by KnightFox
I have a .net solution (say A) with multiple projects(say B,C,D). I want to update all nuget packages for all projects in the solution. I know I can update nuget packages using command line but passing in the path to packages.config
我有一个包含多个项目(比如 B、C、D)的 .net 解决方案(比如 A)。我想更新解决方案中所有项目的所有 nuget 包。我知道我可以使用命令行更新 nuget 包,但传递到 packages.config 的路径
nuget update A/B/packages.config
Is there a way to update packages for all packages.configs inside folder A using command line without having to specify them individually? (I know this can be done from inside visual studio.) Something like
有没有办法使用命令行更新文件夹A中所有packages.configs的包而不必单独指定它们?(我知道这可以从视觉工作室内部完成。)像
nuget update A/*/packages.config
回答by Maxime
As found in NuGet documentation, you can type:
如NuGet 文档中所示,您可以键入:
Update-Package
This will :
这会 :
Update all packages in all projects of the current solution to the latest versions.
将当前解决方案的所有项目中的所有包更新到最新版本。
To open the Package Manager Console:
要打开包管理器控制台:
Tools > NuGet Package Manager > Package Manager Console
工具 > NuGet 包管理器 > 包管理器控制台
Now, in order to have only one instance of all packages, I have, in my solution folder, a file named nuget.configthat contains:
现在,为了只有所有包的一个实例,我在我的解决方案文件夹中有一个名为的文件nuget.config,其中包含:
<configuration>
<config>
<add key="repositoryPath" value="..\Path\To\My\Packages" />
</config>
</configuration>
You might need to reload your solution in order to make it work properly.
您可能需要重新加载解决方案才能使其正常工作。
回答by clairestreb
You have used command line examples, but your question does not state if you require a command line answer. If you do not require command line, you can right-click on your solution in the Solution Explorer, and select Manage NuGet Packages for Solution... This displays a dialog where you can make your selections. Other than that, you'd need to write a script at this point in time anyway (as far as I know).
您已经使用了命令行示例,但是您的问题没有说明您是否需要命令行答案。如果您不需要命令行,您可以在解决方案资源管理器中右键单击您的解决方案,然后选择管理解决方案的 NuGet 包...这将显示一个对话框,您可以在其中进行选择。除此之外,无论如何您都需要在此时编写脚本(据我所知)。
回答by Ekk
First you have to restore all packages using nuget restore solution_file.slnthen update them to latest version by executing nuget update solution_file.sln.
首先,您必须使用恢复所有包,nuget restore solution_file.sln然后通过执行将它们更新到最新版本nuget update solution_file.sln。
Read more about nuget command line
Updated link to Nuget command line documentation
Nuget Package Manager Console documentation (Visual Studio for Windows)
Nuget 包管理器控制台文档(Visual Studio for Windows)
Edit: Previous link is dead. Added working equivalent and bonus Package Manager Console link.
编辑:上一个链接已失效。添加了工作等效和奖励包管理器控制台链接。

