Increasingly, we rely on NuGet Packages in our .NET Development efforts. When you need to add a library to your project, whether it is Entity Framework, AutoMapper, jQuery, etc., NuGet makes that task a simple one. What happens when you are on a plane, train, an automobile - in some circumstance where you are not online and consequently, not connected to your NuGet package source? This is where a local NuGet package source comes in handy. Locally, we can easily stand up an IIS-based NuGet package source. While useful, that is not the simplest thing we can do. Fortunately, the NuGet authors had the foresight and wisdom to allow us to create file directory-based NuGet package sources. This brief article will take you through the steps to create your own local NuGet package source.
Step 1 - Create a Directory
To get started, create a directory to host your local NuGet packages. For purposes of this article, I’ve selected the following directory:
C:\LocalNuGetSource
Step 2 - Get some Packages
Chances are good that you already have some NuGet Packages installed on your system. If you have been working with the pre-release ASP.NET MVC 4 bits, you definitely have local packages. Of course, if you have installed any NuGet Packages from the dialog or the Package Manager Console, you have at least one local NuGet Package. To locate them, simply navigate to your solution’s root folder in Windows Explorer as shown in Figure 1.
Simply copy the folders in the packages directory to the local NuGet package source directory you created in Step 1.
Step 3 - Tell NuGet Where Your Local Package Is
Using the Package Manager Console illustrated in Figure 2, we can easily gain access to the Package Manager Settings. You can also launch the settings dialog from the Package Manager (the Settings button is in the Package Manager Dialog’s lower left-hand corner). Figure 3 illustrates the Package Manager Settings.
At this point, NuGet has all the information it needs to install your packages into selected projects. Figure 4 illustrates how the local feed appears in the NuGet Package Manager.
From here, you can simply select the packages you wish to install, as you would from any other NuGet package source.
Conclusion
That’s all there is to standing up your own local NuGet Feed. You can stand up a server-based feed with NuGet.Server if you want. There are cases where you will want to do that. For example, you may want to use the same mechanism to publish packages as you would with any other NuGet package source. In the case of a file directory-based source, you need direct access to the directory in order to copy, update or delete packages. In any local feed, it’s up to you to make sure the packages are up to date. In many cases, that is desirable since the latest version of a particular package may not be compatible with your software. In many cases, companies shut off access to the official NuGet package source for this reason. With a file directory-based approach, you don’t have to jump through a lot of hoops to make the power of NuGet available to you even in cases when you are not online!