27
votes

I am unable to install/restore nuget packages from a Visual Studio Team Services feed in an asp.net core web application (RC2). I receive the following:

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

I am running Visual Studio Community 2015 Update 2 and nuget version 3.4.4. I am able to install/restore packages from this feed in other project types.

Do I need to do something else to pass my credentials for an asp.net core web app?

Steps to reproduce:

From Team Services package tab I select "Connect to Feed" and copy the NuGet package source URL

In visual studio -> Tools -> NuGet Package Manager -> Package Manager settings -> Package sources and add the feed url from vso

Then from my ASP.NET Core Web Application (.NET Framework) project right click references -> Manage NuGet Packages -> Select my feed from Package source (packages are listed) -> Click to install

In output:

Installing NuGet package xxxxx 
Successfully installed xxxxx to WebApplication1
========== Finished ==========

Then it will try to restore the package at which point I get:

error: Response status code does not indicate success: 401 (Unauthorized).
error: Failed to retrieve information from remote source

And inside web project references - package has warning icon - NU1001 The dependency xxxxx could not be resolved

7
Did you sign in your VSTS account from the upper right corner of VS? Can you share your steps to reproduce this issue?Eddie Chen - MSFT
@Eddie-MSFT - why does signing in even matter? Feeds hosted on NuGet do not require any authorization. I'd rather think that this might be an issue with a proxy that requires authorization in which case signing in does not matter? @HPaxton - do you see the same issue if you try to restore from command line with dotnet restore? Can you check and post feeds you are using - if you do dotnet restore it will show what feeds it used towards the end.Pawel
@Pawel He/She's using a visual studio online feed which is a private feed.Eddie Chen - MSFT
@Eddie-MSFT I am signed in the upper right of visual studio. I am able to add packages from the same vso feed in the same instance of visual studio to a framework class library project.HPaxton
I had the same issue in Visual Studio 2017. Restarting Visual Studio solved the problem for me.keft

7 Answers

16
votes

I can reproduce your issue at my side and following is the workaround I use to restore the packages:

  1. Remove the VSTS feed resource from "VS\Tools\NuGet Package Manager\Package sources".
  2. Open "Packages" tab from your VSTS web portal.
  3. Select the feed you want to connect and click "Connect to feed" option.
  4. Select "Personal Access Tokens" method in the dialog.
  5. Copy the generated command in the dialog.
  6. Run CMD as Administrator on you machine.
  7. Paste the copied command into CMD.
  8. Add "-StorePasswordInClearText" argument after the command.
  9. Run the command.
  10. Restart the VS.
  11. Install and restore the packages.
27
votes

I know that it's not exactly the same issue, but people may come across this one alongside as I did.

I have installed VS Community 2019​ and yesterday I decided to remove the VS 2017, but after that, when I tried to restore the Nuget Packages made by the company, it started displaying an error of 401 Unauthorized.

After a few net searches I decided I didn't want to mess around with VS configurations and files, I then realized, since it's an 404 it's related with an account so what I did was:

  • Closed VS2019
  • Went to windows management credentials and removed all those that where related with my packages
  • Reopened VS 2019 and restored the Nuget Packages for my solution. It them asked for my credentials, set it up and all went well from here.

Here are the two accounts I removed and got recreated:

enter image description here

2
votes

For me, the issue was due to incorrect credentials (not specifying the domain) when connecting to a private on-premise Azure Artifacts NuGet feed, which wasn't immediately apparent.

Using Visual Studio 2019, open NuGet Package Manager for a project. If the 'Browse' tab shows first and the package source is the private NuGet feed, there appears to be no issue as it initially lists all packages. However, switching to the 'Installed' tab results in a login dialogue popping up.

If I enter my username and password without the domain (so username intead of domain/username), it appears to accept this, but then no other versions are listed for my installed packages other than the version installed. If I go to the 'Browse' tab, I then see the following error:

enter image description here

When I click 'Show errors in output', I see the following:

Failed to retrieve metadata from source 'https://[domain]/[Collection]/_packaging/[GUID]/nuget/v3/query2/?q=&skip=0&take=26&prerelease=true&semVerLevel=2.0.0'. Response status code does not indicate success: 401 (Unauthorized).

To resolve this, in Credential Manager, I close Visual Studio, then remove any credentials relating to the Azure DevOps server(e.g., [domain], VSCredentials_[domain]). I noticed that the username for these showed the wrong domain - it showed the Azure DevOps server domain instead of the Active Directory domain.

I then reopen Visual Studio, open NuGet Package Manager again and this time (on the 'Installed' tab) enter my credentials including the domain (domain/username). This resolves the issue and allows me to connect to the Azure Artifact NuGet feed.

1
votes

I had a similar problem (no authentication) in the NuGet Restore task of a VSTS build definition. The solution was to add a NuGet.config file in the root of the project with a reference to the official and my custom feed. Maybe it helps your core project also.

    <?xml version="1.0" encoding="utf-8"?>
<configuration>

  <packageSources>
    <clear />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="RmlrTools" value="https://<MyProjectName>.pkgs.visualstudio.com/DefaultCollection/_packaging/<MyFeedName>/nuget/v3/index.json" />
  </packageSources>
  <!-- used to store credentials -->
  <packageSourceCredentials />
  <!-- Used to specify which one of the sources are active -->
  <activePackageSource>
    <!-- this tells only one given source is active -->
    <add key="NuGet official package source" value="https://nuget.org/api/v2/" />
    <!-- this tells that all of them are active -->
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
  <!-- Used to disable package sources  -->
  <disabledPackageSources />
  <!-- 
  Used to specify default API key associated with sources. 
  See: NuGet.exe help setApiKey
  See: NuGet.exe help push
  See: NuGet.exe help mirror
  -->
  <!--<apikeys>
    <add key="http://MyRepo/ES/api/v2/package" value="encrypted_api_key" />
  </apikeys>-->
</configuration>
1
votes

Try restarting the computer before you try any of the above.

0
votes

In my case , I followed these steps

  1. create the personal access token with relevant credentials
  2. download nuget.exe (nuget cli)
  3. using windows run command open the cmd,then cd C:\Downloads(where the cli is downloaded) ,type "nuget.exe" and enter
  4. execute --> nuget.exe sources Add -Name "MyFeedName" -Source "https://myfeedurl" -username username -password MyAccessToken
  5. in visual studio tools->commandline->developer command prompt
  6. dotnet restore
0
votes
  1. Go to "Manage Nuget Packages"
  2. Click "Setting" from right top Corner
  3. Untick "Packages"

Screenshot