如何让 NuGet 安装/更新 packages.config 中的所有包? [英] How do I get NuGet to install/update all the packages in the packages.config?

查看:67
本文介绍了如何让 NuGet 安装/更新 packages.config 中的所有包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个项目的解决方案.大多数第三方引用都丢失了,但每个项目都有 packages.config 文件.如何让 NuGet 安装/更新所有需要的包?这是否需要通过命令行为每个项目完成?

I have a solution with multiple projects in it. Most of the third party references are missing, yet there are packages.config file for each project. How do I get NuGet to install/update all the packages needed? Does this need to be done via command line for each project?

推荐答案

您可以使用 nuget.exe要恢复您的包或安装 NuGet 2.7 或更高版本,您只需在 Visual Studio 中编译您的解决方案,这也将恢复丢失的包.

You can use nuget.exe to restore your packages or with NuGet 2.7, or above, installed you can simply compile your solution in Visual Studio, which will also restore the missing packages.

对于 NuGet.exe,您可以为每个项目运行以下命令.

For NuGet.exe you can run the following command for each project.

nuget install packages.config

或者使用 NuGet 2.7 您可以恢复解决方案中的所有包 使用命令行.

Or with NuGet 2.7 you can restore all packages in the solution using the command line.

nuget restore YourSolution.sln

这两个都会拉下包.但是,在运行此命令时不会修改您的项目文件,因此该项目应该已经具有对 NuGet 包的引用.如果不是这种情况,那么您可以使用 Visual Studio 安装软件包.

Both of these will pull down the packages. Your project files will not be modified however when running this command so the project should already have a reference to the NuGet packages. If this is not the case then you can use Visual Studio to install the packages.

使用 NuGet 2.7 及更高版本,Visual Studio 将在您构建解决方案时自动恢复丢失的 NuGet 包,因此无需使用 NuGet.exe.

With NuGet 2.7, and above, Visual Studio will automatically restore missing NuGet packages when you build your solution so there is no need to use NuGet.exe.

要更新解决方案中的所有包,首先还原它们,然后您可以使用 NuGet.exe 来更新包或从 Visual Studio 中您可以从包管理器控制台窗口更新包,或者最后您可以使用管理包"对话框.

To update all the packages in your solution, first restore them, and then you can either use NuGet.exe to update the packages or from within Visual Studio you can update the packages from the Package Manager Console window, or finally you can use the Manage Packages dialog.

您可以从命令行将解决方案中的包更新到 nuget.org 提供的最新版本.

From the command line you can update packages in the solution to the latest version available from nuget.org.

nuget update YourSolution.sln

请注意,这不会在任何 NuGet 包中运行任何 PowerShell 脚本.

Note that this will not run any PowerShell scripts in any NuGet packages.

在 Visual Studio 中,您可以使用 Package Manager Console 也更新软件包.这样做的好处是任何 PowerShell 脚本都将作为更新的一部分运行,而使用 NuGet.exe 则不会运行它们.以下命令会将每个项目中的所有包更新到 nuget.org 提供的最新版本.

From within Visual Studio you can use the Package Manager Console to also update the packages. This has the benefit that any PowerShell scripts will be run as part of the update where as using NuGet.exe will not run them. The following command will update all packages in every project to the latest version available from nuget.org.

Update-Package

您也可以将其限制为一个项目.

You can also restrict this down to one project.

Update-Package -Project YourProjectName

如果您想将软件包重新安装到与之前安装的版本相同的版本,那么您可以使用 -reinstall 参数和 Update-Package 命令.

If you want to reinstall the packages to the same versions as were previously installed then you can use the -reinstall argument with Update-Package command.

Update-Package -reinstall

您也可以将其限制为一个项目.

You can also restrict this down to one project.

Update-Package -reinstall -Project YourProjectName

-reinstall 选项将首先卸载软件包,然后将软件包重新安装回项目中.

The -reinstall option will first uninstall and then install the package back again into a project.

或者,您可以使用 Manage Packages 对话框更新包.

Or, you can update the packages using the Manage Packages dialog.

更新:

  • 2013/07/10 - 更新了有关 NuGet 2.7 中 nuget 还原的信息
  • 2014/07/06 - 更新了有关 Visual Studio 中自动包还原的信息,并通过 NuGet 的其他更改更新了答案.
  • 2014/11/21 - 更新了有关 -reinstall
  • 的信息
  • 2013/07/10 - Updated with information about nuget restore in NuGet 2.7
  • 2014/07/06 - Updated with information about automatic package restore in Visual Studio and brought the answer up to date with other changes to NuGet.
  • 2014/11/21 - Updated with information about -reinstall

这篇关于如何让 NuGet 安装/更新 packages.config 中的所有包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆