【问题标题】:"dotnet restore --interactive" doesn't work with Azure Artifacts“dotnet restore --interactive”不适用于 Azure Artifacts
【发布时间】:2019-10-29 09:42:25
【问题描述】:

我有一台新安装的带有 .NET Core SDK 3.0.100 的 Windows 10 机器。我有一个项目,它的 nuget.config 文件包含(以及其他参考)对 Azure Artifacts nuget 提要的引用,我想以交互方式访问此提要的凭据。值得指出的是,我想使用命令行来实现这一点。我选择的 IDE 是 Jetbrains Rider 而不是 Visual Studio(对于这个特定的问题,我不确定这是否重要)。

我已经通过运行 powershell 命令 (Invoke-WebRequest...) 下载了 Azure Artifacts Credential Provider 并成功安装了它 - 看起来很成功。现在我的计算机上有一个 nuget 插件,它可以帮助我检索 azure artifact feed 的凭据。

我希望工作的是运行dotnet restore --interactive 应该提示我输入凭据,但它没有。它根本不提示,只是抱怨找不到包。

我也曾与同事在 MacOS 和 Windows 上尝试过此操作,但似乎总是与此相关的一些问题。任何想法我做错了什么?

感谢您的帮助!

【问题讨论】:

  • 您是否在项目文件夹中运行了该命令? (在哪里 nuget 配置)
  • 我在 .sln 文件所在的同一文件夹中运行 dotnet restore --interactive。在这个文件夹中,我还有一个 .nuget 文件夹,其中包含我的 NuGet.config 文件。

标签: azure-devops nuget


【解决方案1】:

我会回答我自己的问题,因为它可能对其他人有帮助。

当我尝试dotnet restore --configfile .\.nuget\NuGet.Config --interactive 时,它确实提示了我。我可以登录,一切正常!

我不知道为什么,但似乎只是运行 dotnet restore --interactive 并没有选择正确的 nuget 源 - 或者至少不是我在本地项目中在 .\.nuget\NuGet.Config 中定义的那些。因此,凭证提供者(显然)不会提示我做任何事情。我还没有找到任何关于这是预期行为还是错误的详细信息。

【讨论】:

  • This docs page 说:NuGet 3.3 及更早版本使用 .nuget 文件夹进行解决方案范围的设置。 NuGet 3.4+ 中不使用此文件夹。
  • 我花了几天时间才找到你的答案。我一直在努力解决这个问题。谢谢!
【解决方案2】:

当您将nuget.config 文件添加到您的项目时,如果您无法使dotnet restore --interactive 开箱即用,还有另一种选择。

您可以清除所有nuget 本地缓存。

执行此操作的最简单方法是使用以下命令:

dotnet nuget locals all --clear

一段时间后,当所有缓存都被清除后,您可以再次运行dotnet restore --interactive,希望 Azure Artifacts Credential Provider 会向您显示通过设备代码进行身份验证的说明。

【讨论】:

    【解决方案3】:

    使用@Robson Rocha 发布的关于清除所有 nuget 本地缓存的选项,我可以获得凭据说明,但在身份验证后我仍然收到错误:

    warn : The plugin credential provider could not acquire credentials. ...
    error: Response status code does not indicate success: 401 (Unauthorized).
    

    我在我的 Windows 开发环境 creating an Azure Personal Access Token 中解决了这个问题,权限为“Scopes: Custom defined, Packaging: Read”并将其设置在 % AppData% Nuget 文件夹:

    C:\Users\{UserName}\AppData\Roaming\NuGet\NuGet.Config
    

    nuget.config reference - packageSourceCredentials

    <packageSourceCredentials>
      <MyPackageSourceKey>
        <add key="Username" value="myUserName" />
        <add key="ClearTextPassword" value="TheAzurePersonalAccessToken" />
      </MyPackageSourceKey>
    </packageSourceCredentials>
    

    由于 %AppData% Nuget 文件夹是每个用户的,并且它位于 repo 文件夹之外,因此每个用户的凭据都是安全的,我们避免将它们提交到 repo 中。

    【讨论】:

      【解决方案4】:

      您可能需要安装https://github.com/microsoft/artifacts-credprovider#setup,然后才能使用dotnet restore --interactive

      【讨论】:

        猜你喜欢
        • 2022-01-02
        • 2018-02-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-15
        相关资源
        最近更新 更多