Restore NuGet packages from packages.config


Another in my occasional series of wrangling with NuGet within Visual Studio.

This one is to restore all packages from a packages.config file:

  function Restore-Packages() {
    $proj = get-project
    get-package -project $proj.name | % {
      Write-Host $_.id;
      uninstall-package -projectname $proj.name -id $_.id -version $_.version -RemoveDependencies -force ;
      install-package -projectname $proj.name -id $_.id -version $_.version
    }
  }

To use, first edit the packages.config as you require. Then, in the Package Manager Console in VS (in the ‘default project’ dropdown set correctly), just type:

[sourcecode language=”powershell”] Restore-Packages [/sourcecode]

Enjoy.

May 13, 2013 nuget powershell