Search code examples
azure-devopsnugetnuget-packagedotnetcorecli

How to specify an API Key when publishing to a private nuget source in Azure Devops?


I am trying to publish a NuGet package to a NuGet feed I created in Azure Devops. I have experience in doing these kind of things (I published on NuGet.org) but for some reason I do not understand, it is not working when I try to do this for my employer.

When I click "Connect To Feed", I see this explanation:

enter image description here

This clearly shows where to put my package path and where to put the source. However, it does not show where to put the API key I generated.

But I gave it a try and typed (after generating the package file):

dotnet nuget push --source "Test" --api-key az ClassLibrary1.1.0.0.nupkg

This was not working (401)

enter image description here

I really do not understand this part of the explanation: "API Key (any string will do)". Why possibly "any string will do". I need a valid API key.... Not "any string".

After that I tried to publish in way I have good experience with (when publishing nuget.org public nuget packages). In this statement, the source and key are clearly specified.

Here is how I did it:

enter image description here

Also that does not work. I got a 401 again.

My API key that should give me access (and thus prevents a 401) should be fine. This is how I generated the API key:

enter image description here

Most likely, there is something wrong with the way I specified my API key, not with the API key itself. So how do I specify it correctly in my command-line statement in order to successfully publish my package?


Solution

  • There are a few steps you'll have to take before you can push to your NuGet feed locally:

    1. Install the Azure Artifact Credential Provider: https://go.microsoft.com/fwlink/?linkid=2099625
    2. Run dotnet restore --interactive, this will prompt you for credentials
    3. Run dotnet nuget push --source "BackgroundJobs" --api-key anyapikey <package-path>

    Note: You can use any API key.