Creating and using a local NuGet package repository

Vibhav Churi
Mar 27, 2018 · 4 min read

For .NET projects, there is NuGet, the package manager to fulfil the external dependencies in the project. It’s not just limited to the packages that are present on, but there can be multiple package repositories. That’s all nice, but what if you have some home-grown library that you do not want to make publically available? A great use of NuGet packages can be done for class reusability in private projects as well. It is easy to create a NuGet repo on local machine or FTP shared location on your network. How? I’ll show you.

Create a .NET Standard class library for the classes to be shared as a package.

Add your code and public API classes to this library.

namespace VHC.StdLib
public class MathUtils
public static int Square(int number) => number * number;

Go to project properties > Package. Fill assembly details. Check on Generate NuGet package on build. Save.

After completing the project, pack it to create the nupkg file. Technically speaking, a NuGet package is just a ZIP file that’s been renamed with the .nupkg extension and whose contents match certain conventions. To pack a project, build it and then right click it in Solution Explorer and click Pack.

You’ll see the package is created in debug or release folder.

Alternatively, we can use MSBuild to pack (for build scripts) as follows —

msbuild /t:pack /p:Configuration=Release

Make sure NuGet CLI is installed from and is saved in PATH environment variable. Then create a folder accessible to you (local directory or network share) as package repo.

Publish the package to local repo using ‘nuget add’ —

>nuget add VHC.StdLib.1.0.0.nupkg -source d:\source\nuget_repo

Now, let’s take a look at the repository nuget_repo. The package is listed as per version, so it is important to maintain assembly versions while publishing.

Similarly, ‘nuget delete’ is used to delete a package from repo.

Now, we are ready to consume our library from another project. Let’s create another client project using Visual Studio. Right click on the project, and go to Manage NuGet Packages for Solution…

Click the Settings button (little gear icon) next to the Package Source.

We find ourselves in Visual Studio Options for NuGet package sources. These are all the places NuGet looks for dependencies. Let’s add our nuget_repo folder here. Add a new package repo using (+) button and set the path to our source folder. Make sure this one is used before You can arrange the sources by arrow buttons on top right. Click OK when done.

Now, our package can be found and installed via NuGet. 

OR it can be installed using Package Manager Console.

This can then be used like any other package. 

For more in-depth information on this, please refer to the MSDN sources which I learned this from —

Thank you for reading. Please clap to make this article more discoverable.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade