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

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

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.


  • Working great. Thanks for this. But this also begs for being able to run NuGet outside of Visual Studio. It not only avoid having to use a temp solution, but also opens up new possibilities...

  • @Hadi - The NuGet core API's are available outside of Visual Studio - see the NuGet FAQ's here:

    For this specific scenario, you can use the PowerShell script without any NuGet dependency:

    But I generally agree. It would also be nice to be able to run some NuGet packages without having a solution open, although I don't know how that would work.

  • would be nice to have an option that checked the folder specified for NuGetLocal and downloaded, if necessary, newer versions of all packages found in that folder.

  • Can this download specific package names and using wildcards for parameters?

    e.g. I like to download all the EnterpriseLibrary.* packages.

    Is this possible?

  • Really nice script Jon! Thanks.
    A really handy feature would be if the tool could download the latest version of only those packages already present in the destinationDirectory. Then you'd end up with super simple tool for maintaining a selective cache.

  • this is a great idea. however, if you want to create a local repository for a 'real reason', like your server is cut off from the internet and your workstation does not have install permissions, having to get the nuget-downloader from nuget is a chicken-and-egg dilemma.

    Wouldn't it be reasonable to post the actual nuget package on your site so that we can get nuget packages with your tool without having to figure out how to get your nuget package from nuget when that is the problem to begin with?



  • Also, when I try to use the nuget command line to install nuget-downloader, I get an error:

    C:\Active\Install>nuget install nuget.downloader -version

    Could not load file or assembly '0 bytes loaded from System, Version=, Cu
    lture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. An a
    ttempt was made to load a program with an incorrect format.

  • Great Tool Jon!
    But I agree with Daniel, It would be great if this tool could download the latest version of packages already presents in the destination directory.

Comments have been disabled for this content.