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

 


Nuget Package Explorer For Visual Studio

You can open Nuget package with Visual Studio and explore its contents.

choco install nugetpackageexplorer




Documentation

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