Cheatsheet for managing local NuGet packages.

I have finally decided to set up a local NuGet repository for my utilities and libraries. I decided to start small and just create a local repository on my home network.

Below are some quick references for setting up a repository and creating packages.

Set up NuGet for use:

  1. download nuget.exe to a folder in %path%
  2. Create a directory that will be NuGet repository – where all your NuGet packages will be stored (e.g. C:\Programming\NuGet\NuGetRepository)
  3. Within Visual Studio, go to Tools ->Nuget Package Manager Settings -> Package Sources and add the NuGet repository as a source
    • Press +
    • Edit the Name: and Source: fields
    • Press Update

Create a NuGet package:

  1. In Visual Studio, open the solution, right-click the project and select Properties:
    • Set the Assembly name: field the single-word, camel-cased named of the assembly (e.g. ExceptionsLibrary)
    • Select Assembly Information…
      • Set Title: to the text to appear when searching NuGet for the package (e.g. Exceptions Library)
      • Description: text explanation of the purpose of the library (e.g. Exceptions used by the CommonLibraries)
      • Company: to your organization (e.g. C. Pottinger)
      • Assembly Version: Major.Minor.Update.Build
  2. Build in Debug and Release mode
  3. Open cmd prompt in the same directory as the {project}.csproj
>nuget spec {project}.csproj

Edit the {project}.nuspec file:

  1. remove licenseUrl
  2. remove projectUrl
  3. remove iconUrl
  4. set tags
  5. add dependencies (see
 >nuget pack

Add the package to the local repository

>nuget add {project}.{version}.nupkg -source {nugetrepositorydirectory} 

One issue I had was that when adding a package with dependencies, NuGet would fail to find the dependencies. For example, when using NuGet to add package ExtensionsLibrary (which depends on ExceptionsLibrary) I would get:

Unable to resolve dependency 'ExceptionsLibrary'. Source(s) used: '', 'Package source', 'Microsoft Visual Studio Offline Packages'.

The solution that worked for me was to, within Visual Studio, go to the Tools ->Nuget Package Manager Settings -> General and change the Default package management format to PackageReference. Thanks to Babu Annamalai who posted this helpful entry.

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 )

Connecting to %s