Nuget.Downloader package – Download a local NuGet repository using Nuget

22 Oct

by Jon Galloway

NuGet supports multiple feeds, running against either a server or a simple folder / fileshare. See Phil Haack’s post explaining both options for more information. I’m a big believer in running your own local NuGet feed for a lot of reasons – offline access, control over updates, and as an absolute must-have for demonstrations and training. I previously wrote up a NuGet Powershell script which pages through the NuGet OData feed and downloads local copies of the packages. It’s a little more complex than you’d guess, since the script needs to follow redirections and page links, plus I added in some options to skip downloads for features you’ve got, only grab the most popular X packages, etc.

I’d always assumed this would end up as a NuGet package, although the use case is a little out of the ordinary. The primary use case of NuGet is to add things (libraries, code, and content) to an existing application, and this NuGet package doesn’t work at the project level at all. But, it’s just so handy – and there had been enough requests for it – that I couldn’t help myself.

I’d actually started on this when Eric Hexter mentioned that he was working on it as well, so I merged what he’d done, removed all the affiliate ad codes he’d snuck in, and uploaded it yesterday. So, here’s NuGet.Downloader.

2011-03-10 15h46_44


  PM> Install-Package Ext.NET


How to use it

  1. Open a project in Visual Studio (it doesn’t matter which – if you try to install a package outside of a solution, you’ll get slapped down with “The current environment doesn’t have a solution open”).
  2. Open the Package Manager console (View / Other Windows / Package Manager Console).
  3. Type “install-package NuGet.Downloader” – you should see “Successfully installed ‘Nuget.Downloader’.” (with whatever the current version number is).
  4. This adds a new commend to the Package Manager console, Download-Packages. You can run it without any parameters, which will grab the top 500 most popular NuGet packages and drop them in a new LocalNuGet folder inside your My Documents folder.
  5. If desired, uninstall the package using Uninstall-Package.

Parameter options:

  • feedBaseUrl (default: official NuGet package feed, following redirections) – you can point this at a corporate NuGet server or some other location
  • latest (default: $true) – when true, only grabs the latest version of each package
  • overwrite (default: $false) – when true, downloads and overwrites all packages regardless of whether you already have a copy
  • top (default: 500) – number of packages to download, ordered by package popularity. If $null, downloads all packages; if 1 it would download the most popular package
  • destinationDirectory – (default: %HOMEPATH%\Documents\NuGetLocal) full path to the directory you’d like the packages downloaded to. Note: I changed this from LocalNuGet in the Powershell to NuGetLocal in the package, as I thought it made more sense

Example – downloading the top 10 most popular packages with overwrite option, then removing the package:

PM> Install-Package NuGet.Downloader
Successfully installed 'Nuget.Downloader'.   PM> Download-Packages -top 10 -overwrite $true
Downloading latest 10 packages (by download count)
downloading from$filter=IsLatestVersion eq true&$orderby=DownloadCount desc&$top=10
Complete. Local packages saved to C:\Users\Jon\Documents\NuGetLocal
PM> Uninstall-Package NuGet.Downloader
Successfully uninstalled 'Nuget.Downloader'.


Hope it helps you out, and please let me know how I can make it better.

Referenced by:

Leave a comment

Posted by on October 22, 2011 in C#


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: