NuGet
Intro
My notes on the standard, open-source, package manager for the Microsoft development platform, including the popular .NET framework. There is an accompanying tool, Chocolatey that uses the NuGet packages and PowerShell to make it easier to install software.Â
A good introduction can be found here:Â https://docs.microsoft.com/en-us/nuget/what-is-nuget
Get NuGet Client
There are many NuGet clients that can work with a NuGet server:Â https://docs.microsoft.com/en-us/nuget/install-nuget-client-tools. Â All versions of NuGet.exe can be found here:Â https://www.nuget.org/downloads
Â
Install via Chocolatey: choco install nuget.commandline
PS C:\WINDOWS\system32> choco install nuget.commandline
Chocolatey v0.10.15
Installing the following packages:
nuget.commandline
By installing you accept licenses for the packages.
Progress: Downloading NuGet.CommandLine 5.8.1... 100%
NuGet.CommandLine v5.8.1 [Approved]
nuget.commandline package files install completed. Performing other installation steps.
ShimGen has successfully created a shim for nuget.exe
The install of nuget.commandline was successful.
Software install location not explicitly set, could be in package or
default install location if installer.
Chocolatey installed 1/1 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Â
Tips and Tidbits
A NuGet package (.nupkg) is simply a ZIP file so you can change the file extension and open it with any zip explorer. You can also use 7-zip without changing file extension.
NuGet assemblies are never installed machine-wide but rather in the current application's folders, which limits impact to other applications.
A NuGet package doesn't need to contain any assemblies. It can be used just to download dependencies, for example.
NuGet package ID is case-insensitive per https://docs.microsoft.com/en-us/nuget/reference/nuspec#general-form-and-schema
NuGet sources/feeds are stored in the configuration file located in
%AppData%\NuGet\NuGet.Config
(Windows) or~/.nuget/NuGet/NuGet.Config
For debugging, add: -Verbosity detailed.
To see all versions of a package, add:Â -AllVersions
The central NuGet repository, the NugetGallery, can be found here:Â https://www.nuget.org/ and as of 6/2019, it had over 1.7M packages.
There is also a NuGet package explorer which you can download from the Windows App Store. More info here: https://github.com/NuGetPackageExplorer/NuGetPackageExplorer
Package dependencies are specified by name and version. The version syntax and ranges are defined here https://docs.microsoft.com/en-us/nuget/reference/package-versioning#version-ranges-and-wildcards
Dependency resolution is explained in this good article:Â https://docs.microsoft.com/en-us/nuget/consume-packages/dependency-resolution
Â
Nuget Package Explorer For Visual Studio
You can open Nuget package with Visual Studio and explore its contents.
Nuget Package Explorer: https://github.com/NuGetPackageExplorer/NuGetPackageExplorer
choco install nugetpackageexplorer
Documentation
Official documentation can be found at the GitHub home for NuGet:Â https://github.com/nuget/home
Hosting your own private feed:Â https://docs.microsoft.com/en-us/nuget/hosting-packages/overview
To learn how to create your own package, start here:Â https://docs.microsoft.com/en-us/nuget/create-packages/overview-and-workflow
Depends on jQuery 1.4.2
<dependencies>
<dependency id="jQuery" version="[1.4.2]"/>
</dependencies>
Â
Helpful Commands
Create a NuGet package using the .nuspec specified.
Â
Listing Configured Sources / Feeds
Â
Â
Removing Configured Sources / Feeds
Â
Â
Adding NuGet Feeds
NuGet can search in multiple feeds to look for a package. You can add those source locations and specify an alias with the sources add command. The -Name argument can be used as an alias that refers to the full URI. In the example below, I've named my trial version of the Artifactory NuGet server as "Trial".
If the Nuget server requires authentication, you can specify -username <username> -password <password key> with each NuGet command or you can save it in the configuration file as well.
Save authentication information
Â
Saving An API Key
For security purposes, it is best to save a revocable API key rather than the cleartext or encrypted password (as shown above). You need to generate the key in the Nuget Server (eg Artifactory).
Â
API Key
Pushes the specified NuGet package to the NuGet feed named "Artifactory"
List all NuGet packages in a source named "Artifactory"
List local NuGet caches.
List all installed NuGet packages. The Source comes from the global-packages in the command above
Find package in the feed Artifactory and install it.
To Install a local package, you must first add a feed to the path where the package is found.
Â
Where Does NuGet Keep Its Configuration?
Nuget keeps its configuration data in NuGet.config which can be found at %appdata%\NuGet\NuGet.Config in Windows or ~/.config/NuGet/NuGet.Config in Linux
For example, when you defined an Nuget feed (source)Â with:
Configuration - Aliases
That information is maintained in Nuget.config as a <packageSoruces> entry:
Nuget.config
References
Wikipedia:Â https://en.wikipedia.org/wiki/NuGet
A blog on NuGet versioning:Â http://blog.davidebbo.com/2011/01/nuget-versioning-part-1-taking-on-dll.html