3

The documentation here says

To publish to an external NuGet feed, you must first create a service connection to point to that feed....

It then provides this YAML:

- task: NuGetAuthenticate@0
  inputs:
    nuGetServiceConnections: '<Name of the NuGet service connection>'
- task: NuGetCommand@2
  inputs:
    command: push
    nuGetFeedType: external
    versioningScheme: byEnvVar
    versionEnvVar: <VersionVariableName>

This fails with

"Error: The service connection for 'https://api.nuget.org/v3/index.json' is not valid. ApiKey service connections are not supported in this task. Instead, use -ApiKey (NuGet) or --api-key (dotnet) when invoking the tool itself. See the task documentation for more details."

I have created a service connection that points to nuget.org with my ApiKey.

I do not understand this portion of the error message: "Instead, use -ApiKey (NuGet) or --api-key (dotnet) when invoking the tool itself. See the task documentation for more details."

I have also seen this question which refers to a deficiency which has since been implemented.

Edit: Turns out the deficiency mentioned above is a red herring. The real problem is a limitation of nuget which still exists as of this writing.

1 Answers1

4

According to the NuGet Authenticate task document:

Some package sources such as nuget.org use API keys for authentication when pushing packages, rather than username/password credentials. Due to limitations in NuGet, this task cannot be used to set up a NuGet service connection that uses an API key.

Instead:

  1. Configure a secret variable containing the ApiKey

  2. Perform the package push using nuget push -ApiKey $(myNuGetApiKey) or dotnet nuget push --api-key $(myNuGetApiKey), assuming you named the variable myNuGetApiKey

Jane Ma-MSFT
  • 4,461
  • 1
  • 6
  • 12
  • 3
    AFAIK there is not a single Microsoft document that provides a working example of how to publish a nuget package to the largest nuget package repository on the planet, nuget.org. The only end-to-end example I know of is provided by [KUTline](/u/KUTline) and can be found [here](https://stackoverflow.com/a/64178172/3230660). –  Mar 17 '21 at 15:27