41

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

Esther Fan - MSFT
  • 8,276
  • 4
  • 27
  • 25
HPaxton
  • 443
  • 1
  • 4
  • 8
  • 1
    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 Jun 22 '16 at 04:31
  • @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 Jun 22 '16 at 05:47
  • @Pawel He/She's using a visual studio online feed which is a private feed. – Eddie Chen - MSFT Jun 22 '16 at 05:51
  • @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 Jun 22 '16 at 11:29
  • @Pawel I get the same 401 Unathorized error from command line – HPaxton Jun 22 '16 at 11:29
  • 2
    I had the same issue in Visual Studio 2017. Restarting Visual Studio solved the problem for me. – keft Jan 11 '18 at 15:08
  • @keft Same here! – Tom Troughton Feb 03 '18 at 10:12
  • 1
    Sign out & sign in with my account in Visual Studio solved the issue. – Heinzlmaen Jan 20 '21 at 08:54

11 Answers11

38

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 401 Unauthorized 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

Isaac Abramowitz
  • 542
  • 5
  • 17
Pimenta
  • 1,029
  • 2
  • 13
  • 32
  • This fixed it for me. Thanks! I just removed any credential that referenced my company's NuGet feed. – Neo Aug 19 '19 at 09:40
  • this worked for me too. I just updated the pw for "VSCredentials_[whatever]" cred under Generic Credentials, restarted VS 2019 and it started working. – Chuck Mar 04 '20 at 17:39
31

In my case I was using an azure dev ops feed. After updating visual studio 2022 I started getting this message "Response status code does not indicate success: 401 (Unauthorized)."

I followed and tried most of the solutions here. but what worked for me was to

  • Go to: file -> accounts settings
  • Click "sign out"
  • Then go to the nuget manager and click the refresh button
  • This will then show you the azure dev ops login window where you login to your account

This worked for me, (your mileage may vary) just hope it helps someone else and saves some precious receding hairs.

Thorgeir
  • 3,960
  • 3
  • 24
  • 20
  • 1
    Didn't believe it. But this worked. Thanks. Commenting here, so that people can try this out save some time. – Vivek Verma Aug 17 '22 at 07:10
  • Worked for me as well. However, I had two instances of Visual Studio open and had to do the steps in the one which had the project open for which I wanted to build the NuGet-package. – mamen Apr 18 '23 at 14:08
  • This is what worked for me also. I was still able to auth fine in VS 2019 using the same account to connect to the same Azure devops feed, just not for VS 2022. These steps fixed the issue in VS 2022, except that I had to remove the account rather than just sign out – thomb1602 May 22 '23 at 14:58
  • Awesome! this worked for me too. All I did was pull latest from git and got myself into this. Thank you for the help! – Adrian Garcia May 26 '23 at 15:18
18

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.
Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
  • I had the same issue, so I followed your way of using PAT instead. Now at least I get a different error as follows. Password decryption failed for source : 'https://****.pkgs.visualstudio.com/_packaging/myfeed/nuget/v3/index.json' is unsupported on this platform. A clear text password may be used instead. – SamDevx Jun 23 '16 at 06:09
  • @SamDevx Check step 8. I get that error message too without step 8. – Eddie Chen - MSFT Jun 23 '16 at 06:13
  • sorry my bad, it works now. Your workaround rocks!! Key here is using the PAT as you suggested but modifying with -StorePasswordInClearText switch. I can finally move ahead with the project. At some point though, they (nuget or .NET Core team) need to fix this terrible issue. – SamDevx Jun 23 '16 at 06:32
  • Works perfectly. Good stuff! Thanks – HPaxton Jun 23 '16 at 12:17
  • 2
    We've added this workaround to the documentation for VSTS NuGet feeds: https://www.visualstudio.com/en-us/docs/package/get-started/nuget/auth#dotnet-core – Alex Mullans Jun 23 '16 at 20:19
4

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.

Neo
  • 4,145
  • 6
  • 53
  • 76
3

This happens when you change your profile password. Just sign out and from top right (at your profile picture-> account settings); sign in again and your problem will be solved.

1

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>
Frederic
  • 633
  • 5
  • 12
1

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

Venkata K. C. Tata
  • 5,539
  • 4
  • 22
  • 35
1

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
Heshan
  • 772
  • 8
  • 22
1
  1. Go to "Manage Nuget Packages"
  2. Click "Setting" from right top Corner
  3. Untick "Packages"

Screenshot

bguiz
  • 27,371
  • 47
  • 154
  • 243
A. Salano
  • 21
  • 1
1

In my case I was using Azure Devops private feed and the NuGet package restoring worked in Visual Studio and in Nuget CLI but it didn't work with Rider and dotnet restore command

The solution was to install The Azure Artifacts Credential Provider and it fixed the problem. I just had to run this command to install it:

iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) }"

This is a fix for a local developer machine. For fixing it on CI/CD check this question.

Mariusz Pawelski
  • 25,983
  • 11
  • 67
  • 80
0

I'm using VS 2022. The way I was able to fix it is to relog into VS. The trick is the tooltip on the top right SAYS I'm logged in, but when you click your profile logo on the top right, then goto Account Settings, it told me I needed to "reenter my credentials". How does that work, I'm logged in, but I'm not logged in? Turns out it doesn't work, I needed to log in AGAIN for it to REALLY work.

PHenry
  • 287
  • 3
  • 16
  • Thanks for the comment. You had to re-enter them as well, and it helped? Awesome. I had another coworker have this happen to them as well. Helped two others, great! :> – PHenry Sep 27 '22 at 17:19