【问题标题】:Adding PackageReference for package fails with 401 (Unauthorized)为包添加 PackageReference 失败,出现 401(未经授权)
【发布时间】:2021-06-23 19:27:32
【问题描述】:

我正在尝试将第三方 NuGet 包(例如 StyleCop)安装到项目中。该项目还包含从我们自己的私有 NuGet 源安装的包。尝试安装软件包时,我们收到这样的 401 错误。

MyProject> dotnet add .\MyProject.csproj package StyleCop
  Determining projects to restore...
  Writing C:\Users\me\AppData\Local\Temp\tmp6A51.tmp
info : Adding PackageReference for package 'StyleCop' into project '.\MyProject.csproj'.
info :   CACHE https://api.nuget.org/v3/registration5-gz-semver2/stylecop/index.json
info :   GET https://mediavaletsc.pkgs.visualstudio.com/_packaging/c559332f-5d8d-4d3f-8fc2-6e06125775fa/nuget/v3/registrations2-semver2/stylecop/index.json
info :   Unauthorized https://mycompany.pkgs.visualstudio.com/_packaging/xxx-xxx-xxx-xxx-xxx/nuget/v3/registrations2-semver2/stylecop/index.json 680ms
error: Response status code does not indicate success: 401 (Unauthorized).

奇怪的是,运行 dotnet restore 运行良好,即使在运行 git clean -xfd 之后也是如此。我们如何配置dotnet 和/或nuget 以接受StyleCop 或任何其他公共包的安装?

【问题讨论】:

    标签: authentication .net-core azure-devops nuget dotnet-cli


    【解决方案1】:

    我们需要使用 Visual Studio Team Services (VSTS) 重新进行身份验证,因为 API 密钥已过期和/或被撤销。

    dotnet restore 仍然可以工作,但dotnet add ... package ... 失败的原因是前者使用了本地缓存,而后者则访问了服务器。在我们运行 nuget locals all -clear 之后,Restore 也停止工作。

    要重新进行身份验证,请执行以下操作。

    nuget sources remove -name $sourceName | Out-Null;
    nuget sources add -name $sourceName -source $sourcePath -username $username -password $apiKey
    

    【讨论】:

    • 您好,感谢您的分享,您可以Accept it as an Answer,它可以帮助遇到同样问题的其他社区成员,谢谢。
    • 完成。感谢@EdwardHan-MSFT 的反馈。
    猜你喜欢
    • 2017-11-13
    • 1970-01-01
    • 2012-06-30
    • 2021-01-08
    • 2018-01-25
    • 1970-01-01
    • 2013-01-01
    • 2020-07-07
    • 1970-01-01
    相关资源
    最近更新 更多