This document describes the steps to add, remove or restore NuGet packages in your application when the build environment does not include Visual Studio (e.g. you are developing a .Net Core application using a text editor and the dotnet CLI, using Visual Studio Online, or configuring package restore in a build rig) .
See Installing NuGet client tools for approaches to installing the Nuget CLI on Windows, MacOS and Linux.
Authenticating to the NuGet feed
To enable automatic authentication when using the dotnet or nuget CLIs you will need to store your Software Potential credentials in a NuGet.Config file (see a sample here).
The config file can be manually created in a text editor and saved to one of three locations on the dev/build machine depending on whether the configuration is intended to operate in project, user or machine level scope (see Microsoft reference for configuring NuGet behavior).
For example, on a Linux machine the following config file could be saved as NuGet.Config at ~/.nuget/NuGet for user level scope:
<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="https://www.nuget.org/api/v2/" value="https://www.nuget.org/api/v2/" /> <add key="SoftwarePotential" value="https://srv.softwarepotential.com/NuGet/nuget" /> </packageSources> <packageSourceCredentials> <SoftwarePotential> <add key="Username" value="user" /> <add key="ClearTextPassword" value="my_password" /> </SoftwarePotential> </packageSourceCredentials> </configuration>
Alternatively, if the nuget CLI is installed, you can create a minimal config file manually, and then use the CLI to set the required values on the command line. On Windows, this has the advantage of encrypting the stored password. To do this:
- First create a new empty config file by saving the following xml template at the appropriate location e.g. in ~/.nuget/NuGet:
<?xml version="1.0" encoding="utf-8"?> <configuration> </configuration>
- Run the following command to set the Software Potential feed source and your user credentials:
nuget sources add -Name "SoftwarePotential" -source "https://srv.softwarepotential.com/NuGet/nuget" -User "user" -pass my_password -configFile "~/.nuget/NuGet/NuGet.Config"
- This will also add the default NuGet source.
- If you are adding credentials to the SoftwarePotential source already configured in the Nuget.config file please use the “Update” option rather than "Add" (as duplicate entries for a source are not permitted).
- Encrypted passwords are not supported on platforms other than Windows at the time of writing. In Linux or MacOs environments the --StorePasswordInClearText option should be added to this command.
Managing NuGet Packages
Once authenticated to the Software Potential source you can access your NuGet packages for installation in your projects. The NuGet feed can serve multiple versions of a given NuGet Permutation package and multiple revisions of each version.
Adding or Removing Packages
Packages can be added to and removed from your project from the command line using the dotnet CLI
dotnet add package SoftwarePotential.Protection-<YourPermutationShortcode>
dotnet remove package SoftwarePotential.Protection-<YourPermutationShortcode>
Packages are restored by the "dotnet restore" command. In addition, packages are restored by default by all commands that require a restore to occur, such as "dotnet new", "dotnet build" and "dotnet run" (see dotnet restore reference).