Reinstalling NuGet packages with NuGet installed as VS Extension
Solution 1
As an update to this post, NuGet 1.6 added support for the workflow to restore the packages at build time if missing. Right-Click on the solution, click "Enable Package Restore Mode" to set it on.
More details at: http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages
Solution 2
Reinstall all packages in all projects of the current solution:
Update-Package -Reinstall
You can find more information about reinstalling nuget packages here
Solution 3
Warning - using
Update-Package -Reinstall
or
Update-Package -Reinstall -IgnoreDependencies
may remove all of your packages and package.config files!
Always make sure that you have your backups performed first.
Scenario:
- Solution with multiple projects
- Each contains their own Nuget entries, some with the same packages (e.g., SharpRepository, Entity Framework)
- Now copy folder without the packages folder for "distribution" somewhere else
- Assume the packages folder wasn't included with the distribution
- Now try the command
Update-Package -Reinstall
or if you have some alpha packages and/or are sure your dependencies are good, tryUpdate-Package -Reinstall -IgnoreDependencies
Result:
Because the packages folder doesn't exist, the entries for your packages methodically go away, too. This can surprise some people - so be careful, is all I'm saying.
Solution 4
Found the solution on This blog entry. I needed to install NuGet.CommandLine, which makes nuget.exe. globally available in the VS command line. I can then set this up as a pre-build event to ensure that dependencies are downloaded.
Solution 5
A much easier option that you can keep enabled in Visual Studio during development to ease off your NuGet package installation related pain.
Keep both below mentioned options under NuGet Package Manager
> General
in checked state -
- Allow NuGet to download missing packages
- Automatically check for missing packages during build in Visual Studio
Have a look at the screenshot below:
AlexWilson
Updated on August 24, 2020Comments
-
AlexWilson over 3 years
I would like to be able to install all of the NuGet packages in the packages.config, as per The NuGet docs. NuGet is installed as a VS Extension, and I can't seem to find nuget.exe. Is it possible to run:
nuget i packages.config -o Packages
Without maintaining a seperate copy of nuget.exe on a per project basis?
-
davidfowl over 12 yearsEven better solution docs.nuget.org/docs/workflows/…
-
Tim Long about 10 yearsYou don't need any pre-build events, you can 'Enable NuGet package restore' and it will integrate NuGet with your build. Note that when you do this, a .nuget folder is creates that you need to commit to version control. The .nuget folder contains a copy of nuget.exe - if you don't want to commit that file, there is a tweak you can make in the nuget.targets file that will make it download nuget.exe as necessary.
-
onof about 10 yearsThis command also updates all packages to newer versions, doesn't it?
-
Rodolpho Brock about 10 yearsDon't, this just reinstall!
-
rajeemcariazo over 8 yearsthe second one worked after getting an error "the type or namespace name does not exist in the namespace"
-
smg over 7 yearsIt updates when there is no old version available on nuget.org.