Reinstalling NuGet packages with NuGet installed as VS Extension

41,820

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, try Update-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 -

  1. Allow NuGet to download missing packages
  2. Automatically check for missing packages during build in Visual Studio

Have a look at the screenshot below:

enter image description here

Share:
41,820
AlexWilson
Author by

AlexWilson

Updated on August 24, 2020

Comments

  • AlexWilson
    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
    davidfowl over 12 years
    Even better solution docs.nuget.org/docs/workflows/…
  • Tim Long
    Tim Long about 10 years
    You 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
    onof about 10 years
    This command also updates all packages to newer versions, doesn't it?
  • Rodolpho Brock
    Rodolpho Brock about 10 years
    Don't, this just reinstall!
  • rajeemcariazo
    rajeemcariazo over 8 years
    the second one worked after getting an error "the type or namespace name does not exist in the namespace"
  • smg
    smg over 7 years
    It updates when there is no old version available on nuget.org.