If you have a .NET Core project which references a NuGet package from a private VSTS 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 VSTS personal access token (PAT). This article shows how to do that.
1. Create personal access token (PAT) on VSTS
Navigate to your VSTS 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
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 VSTS site under “Packages” > “Connect to feed”.
Keep in mind, that the PAT is locally stored without encryption in the machine’s NuGet.config file.
Tags: .NET Core, CLI, NuGet, VSTS