A recent network “hiccup” posed a bit of a challenge to a demo that was built around showing how the Windows Azure Toolkit for Windows Phone (WATWP) NuGet packages make it easy to add Windows Azure cloud features to a Windows Phone 7 application.  So how do you access NuGet content when a network connection isn’t available?  What if you want to exert some management over the updates that are exposed to the developers in your enterprise, including exposing often-used or internal-use assets?

It turns out that NuGet offers some functionality that addresses these scenarios.  In addition to supporting the ability to set up your own package server (also known as Creating Remote Feeds in the NuGet documentation), there is the ability to consume packages collected in a directory – either a network share or a local file-system folder.  This is illustrated in the NuGet documentation under the subtopic “Creating Local Feeds” within the “Hosting Your Own NuGet Feeds” topic.

Populating a File-System Based Package Store

Any folder that contains NuGet .nupkg files can be set to be as a file-system based package server.  From my own use, folders that contain subfolders with .nupkg files will also work, allowing for organization and hierarchy.  If you already have a Visual Studio solution that has references to NuGet packages, moving these packages into such a local package store can be quite simple (especially for demos!)  Just locate the “packages” folder that is created when the NuGet packages are added

image

The entire package folder is not required, since the nupkg files are really Zip files that contain all of the necessary contents.  Search for files that end with the .nupkg extension.

SNAGHTML9fbf7a

Simply copy all of these files into the folder you are using for your file-system based package store.  Note that a wider set of packages is available in your local package cache, which is normally maintained in <UserFolder>AppDataLocalNuGetCache, and can be accessed from Visual Studio via Tools-Library Package Manager-Package Manager Settings, and click the “Browse” button in the General section of the Package Manager settings node.

Using File-Based Package Stores

To tell Visual Studio to consume file-based package stores, bring up the settings dialog (via Tools-Library Package Manager-Package Manager Settings or through the other accessors in Visual Studio) and select the Package Sources section of the Package Manager settings node.  Provide a name and type in the path or browse to the package location and click the Add button.  Note that the elements in the Available Package Sources list are shown in a check-list-box – they can be enabled or disabled.  Elements in the list can also be reordered in order to determine the precedence in which the sources are searched for matching packages.

SNAGHTMLab5b5b

When adding NuGet package references to your project in Visual Studio via the Manage NuGet Packages dialog, note that the newly named source now appears within the “Online” package listing section.

SNAGHTMLb09c32

The new source is also available as a pulldown option in the Package Manager Console window.

SNAGHTMLb430e2

As I’ve been digging into NuGet more lately, I’ve been quite impressed by the functionality it exposes.  There’s much more to it than just a right-click menu item and a dialog box  that adds and updates project assembly references.  Some of my current favorites include managing package references at the solution level and visualizing NuGet package chains.  Be sure to check out the NuGet docs in case you have yet to discover your favorite.