How do I get NuGet to install/update all the packages in the packages.config?
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?
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.
For NuGet.exe you can run the following command for each project.
nuget install packages.config
Or with NuGet 2.7 you can restore all packages in the solution using the command line.
nuget restore YourSolution.sln
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.
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.
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.
From the command line you can update packages in the solution to the latest version available from nuget.org.
nuget update YourSolution.sln
Note that this will not run any PowerShell scripts in any NuGet packages.
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
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
The -reinstall
option will first uninstall and then install the package back again into a project.
Or, you can update the packages using the Manage Packages
dialog.
Updates:
-reinstall
Reinstall all packages in ALL PROJECTS of the current solution:
Update-Package -Reinstall
Reinstall all packages in SPECIFIC PROJECT of the current solution (Thanks to unarity and ashes999):
Update-Package -ProjectName 'YourProjectNameGoesHere' -Reinstall
There is another, newer and quicker way to do this from within Visual Studio. Check out this post by David Ebbo, and reference the comments section if you run into trouble. Basically, you do the following in Package Manager prompt:
PM> Install-Package NuGetPowerTools
PM> Enable-PackageRestore
Afterwards, when you build your solution the packages will be automatically installed if they're missing.
Update:
This functionality is built into Nuget 1.6 with visual studio integration so you don't even need to install NuGetPowerTools or type commands. All you have to do is
Right click on the Solution node in Solution Explorer and select Enable NuGet Package Restore.
Read this article for more details.
链接地址: http://www.djcxy.com/p/62274.html