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%
    1. see here for more details

Create a NuGet package:

  1. Update the Properties -> Assembly Information for the project
    • Ensure Title and Assembly Version properly set
  2. Build in Debug and Release mode
  3. Open cmd prompt in the same library as the {project}.csproj
>nuget spec {project}.csproj

Edit the {project}.nuspec file:

  1. remove licenseUrl
  2. remove projectUrl
  3. remove iconUrl
  4. set authors = {my name}
  5. set description = match Description from Assembly Information
  6. set releaseNotes
  7. set copyright
  8. set tags
  9. add dependencies
 >nuget pack

Add the package to the local repository

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

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: 'nuget.org', 'Package source', 'Microsoft Visual Studio Offline Packages'.

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google 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