From 328e78afc04e7a5471b1a338930bc572fa2a9523 Mon Sep 17 00:00:00 2001 From: Andy Zivkovic Date: Thu, 23 Apr 2026 10:43:09 +0930 Subject: [PATCH] Add docs on api key environment variables --- docs/create-packages/Symbol-Packages-snupkg.md | 4 ++++ docs/quickstart/includes/publish-dotnet.md | 4 ++++ docs/reference/cli-reference/cli-ref-environment-variables.md | 2 ++ docs/reference/cli-reference/cli-ref-push.md | 4 ++-- docs/reference/cli-reference/cli-ref-setapikey.md | 4 ++++ docs/reference/nuget-config-file.md | 4 ++++ 6 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/create-packages/Symbol-Packages-snupkg.md b/docs/create-packages/Symbol-Packages-snupkg.md index ea43a75f9..940095aa5 100644 --- a/docs/create-packages/Symbol-Packages-snupkg.md +++ b/docs/create-packages/Symbol-Packages-snupkg.md @@ -73,6 +73,10 @@ The [`SymbolPackageFormat`](/dotnet/core/tools/csproj#symbolpackageformat) prope nuget SetApiKey Your-API-Key ``` + > [!TIP] + > Starting with NuGet 7.6, you can set the `NUGET_API_KEY` and `NUGET_SYMBOL_API_KEY` environment variables instead of using `SetApiKey`. + > For more information, see [environment variables](../reference/cli-reference/cli-ref-environment-variables.md). + 1. After publishing your primary package to nuget.org, push the symbol package as follows. ```cli diff --git a/docs/quickstart/includes/publish-dotnet.md b/docs/quickstart/includes/publish-dotnet.md index d0ccbb8c7..f5d73e624 100644 --- a/docs/quickstart/includes/publish-dotnet.md +++ b/docs/quickstart/includes/publish-dotnet.md @@ -4,6 +4,10 @@ From the folder that contains the *.nupkg* file, run the following command. Repl dotnet nuget push --api-key --source https://api.nuget.org/v3/index.json ``` +> [!TIP] +> Starting with NuGet 7.6 (.NET SDK 10.0.300), you can set the `NUGET_API_KEY` environment variable instead of passing `--api-key` on the command line. +> This is useful in CI/CD scenarios where you don't want to pass the key as a command-line argument. + The output shows the results of the publishing process: ```output diff --git a/docs/reference/cli-reference/cli-ref-environment-variables.md b/docs/reference/cli-reference/cli-ref-environment-variables.md index e0c993671..34b300187 100644 --- a/docs/reference/cli-reference/cli-ref-environment-variables.md +++ b/docs/reference/cli-reference/cli-ref-environment-variables.md @@ -37,5 +37,7 @@ The list of properties documented in [NuGet pack and restore as MSBuild targets] | NUGET_XMLDOC_MODE | Determines how assemblies XML documentation file extraction should be handled. | Supported modes are *skip* (do not extract XML documentation files), *compress* (store XML doc files as a zip archive) or *none* (default, treat XML doc files as regular files). | | NUGET_CERT_REVOCATION_MODE | Determines how the revocation status check of the certificate used to sign a package, is performed when a signed package is installed or restored. When not set, defaults to `online`.| Possible values *online* (default), *offline*. Related to [NU3028](../errors-and-warnings/NU3028.md) | | NUGET_ENHANCED_MAX_NETWORK_TRY_COUNT | Configures the maximum number of times an HTTP connection should be retried when enhanced retries are enabled. | A number representing how many retries to perform, the default value is `6`. | +| NUGET_API_KEY | The API key used to authenticate when pushing packages. If not set, the value from the `apikeys` section of `NuGet.Config` is used. | Available in NuGet 7.6 and higher. The command-line option takes precedence over this environment variable. | +| NUGET_SYMBOL_API_KEY | The API key used to authenticate when pushing symbol packages. If not set, the value from the `apikeys` section of `NuGet.Config` is used. | Available in NuGet 7.6 and higher. The command-line option takes precedence over this environment variable. | | NUGET_ENHANCED_NETWORK_RETRY_DELAY_MILLISECONDS | Configures the amount of time to wait in milliseconds before retrying an HTTP connection when enhanced retries are enabled. | Number of millseconds to wait, the default value is `1000`. | diff --git a/docs/reference/cli-reference/cli-ref-push.md b/docs/reference/cli-reference/cli-ref-push.md index cdb3fef24..b5ec51498 100644 --- a/docs/reference/cli-reference/cli-ref-push.md +++ b/docs/reference/cli-reference/cli-ref-push.md @@ -33,7 +33,7 @@ where `` identifies the package to push to the server. - **`-ApiKey`** - The API key for the target repository. If not present, the one specified in the config file is used. + The API key for the target repository. If not present, the `NUGET_API_KEY` environment variable is read *(7.6+)*. If neither is set, the one specified in the config file is used. - **`-ConfigFile`** @@ -77,7 +77,7 @@ where `` identifies the package to push to the server. - **`-SymbolApiKey`** - *(3.5+)* Specifies the API key for the URL specified in `-SymbolSource`. + *(3.5+)* Specifies the API key for the URL specified in `-SymbolSource`. If not present, the `NUGET_SYMBOL_API_KEY` environment variable is read *(7.6+)*. If neither is set, the one specified in the config file is used. - **`-Timeout`** diff --git a/docs/reference/cli-reference/cli-ref-setapikey.md b/docs/reference/cli-reference/cli-ref-setapikey.md index a594048e8..1b2f7f136 100644 --- a/docs/reference/cli-reference/cli-ref-setapikey.md +++ b/docs/reference/cli-reference/cli-ref-setapikey.md @@ -13,6 +13,10 @@ ms.topic: reference Saves an API key for a given server URL into `NuGet.Config` so that it doesn't need to be entered for subsequent push commands. +> [!TIP] +> Starting with NuGet 7.6, you can also set the `NUGET_API_KEY` environment variable to provide an API key for push operations without storing it in `NuGet.Config`. +> For more information, see [environment variables](cli-ref-environment-variables.md). + ## Usage ```cli diff --git a/docs/reference/nuget-config-file.md b/docs/reference/nuget-config-file.md index 9778073f9..941d04526 100644 --- a/docs/reference/nuget-config-file.md +++ b/docs/reference/nuget-config-file.md @@ -252,6 +252,10 @@ When using unencrypted passwords: Stores keys for sources that use API key authentication, as set with the [`nuget setapikey` command](../reference/cli-reference/cli-ref-setapikey.md). +> [!NOTE] +> Starting with NuGet 7.6, the `NUGET_API_KEY` and `NUGET_SYMBOL_API_KEY` environment variables can also provide API keys for push operations. +> The command-line option takes precedence over the environment variable, and the environment variable takes precedence over keys stored in `NuGet.Config`. + | Key | Value | | --- | --- | | (source URL) | The encrypted API key. |