Unauthorized nuget package from Visual Studio Team Services using asp.net core rc2

瘦欲@ 提交于 2019-12-03 12:53:31

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.

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:

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>

Also, here is the documentation showing how you should do it in the section ".NET Core".

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:

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!