Rico Suter's blog.
 

If you have a .NET Core project which references a NuGet package from a private Azure DevOps package feed, you cannot just build the project in CLI because you are not authorized to access the feed: When running dotnet restore, you’ll end up with this error message:

error: Response status code does not indicate success: 401 (Unauthorized).

To fix this problem, you can register the private NuGet feed with a Azure DevOps personal access token (PAT). This article shows how to do that.

1. Create personal access token (PAT) on Azure DevOps

Navigate to your Azure DevOps site, go to the “Security” settings (top right), click on “Personal access tokens” and click on the “Add” button:

Select only “Packaging (read)” and create a token, then copy the generated token into your clipboard for later use (after closing this page, you can no longer access the token).

2. Download nuget.exe

Go to the NuGet page and download nuget.exe:

https://www.nuget.org/downloads

3. Register package feed with personal access token

After generating a token and downloading nuget.exe, register the private NuGet feed with the following command:

nuget.exe sources Add -Name "MyFeedName" -Source "https://myfeedurl" -username unused -password MyAccessToken

The source URL can be found on the Azure DevOps site under “Packages” > “Connect to feed”.

Keep in mind, that the PAT is locally stored without encryption in the machine’s NuGet.config file.



Discussion