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:
- download nuget.exe to a folder in %path%
- Create a directory that will be NuGet repository – where all your NuGet packages will be stored (e.g. C:\Programming\NuGet\NuGetRepository)
- 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:
- 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
- Build in Debug and Release mode
- Open cmd prompt in the same directory as the {project}.csproj
>nuget spec {project}.csproj
Edit the {project}.nuspec file:
- remove licenseUrl
- remove projectUrl
- remove iconUrl
- set tags
- add dependencies (see https://docs.microsoft.com/en-us/nuget/reference/nuspec#dependencies-element)
>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: 'nuget.org', '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.