【问题标题】:How to run `dotnet list package --deprecated` for Azure Artifact feed on Azure Pipelines如何在 Azure Pipelines 上为 Azure Artifact 源运行“dotnet list package --deprecated”
【发布时间】:2021-02-05 14:00:19
【问题描述】:

我正在尝试为使用 Azure Artifact 源中的包的项目运行 dotnet list package --deprecated

我把它包裹在DotNetCoreCLI任务中:

  - task: DotNetCoreCLI@2
    displayName: 'List deprecated packages'
    continueOnError: true
    inputs:
      command: custom
      custom: list
      arguments: 'package --deprecated'

我在nuget.config 文件中配置了源,并且在我使用dotnet restore 时效果很好。但是,当我运行 list package 时,我有:

The following sources were used:
   https://api.nuget.org/v3/index.json
   https://pkgs.dev.azure.com/...../nuget/v3/index.json
   https://pkgs.dev.azure.com/......./nuget/v3/index.json

然后:

错误:响应状态码不表示成功:401(未授权)。

我尝试通过以下方式显式添加来源:

  - script: |
      nuget sources add -name "Source1" -source https://pkgs.dev.azure.com/...../nuget/v3/index.json -username anything -password %SYSTEM_ACCESSTOKEN%
      nuget sources add -name "Source2" -source https://pkgs.dev.azure.com/...../nuget/v3/index.json -username anything -password %SYSTEM_ACCESSTOKEN%
    enabled: false
    env:
      SYSTEM_ACCESSTOKEN: $(System.AccessToken)
    displayName: Add NuGet source

但这失败了,因为:

The source specified has already been added to the list of available package sources. Provide a unique source.
The source specified has already been added to the list of available package sources. Provide a unique source.

我还修改了Allow project-scoped builds的权限:

我还在 GitHub dotnet list package --outdated` doesn't work with sources that need auth #7605 上找到了这个主题,尽管现在已经关闭,但我没有看到太多帮助。

当我使用 --interactive 标志在本地运行此程序时,系统会不断提示我登录:

但是,dotnet restore 有效。我尝试了所有想到的东西,但仍然没有任何进展。它不适用于本地和 Azure Pipelines。

你知道我做错了什么吗?

【问题讨论】:

  • nuget list/dotnet list package 有点奇怪,最后我检查了使用 nuget 2.x 天的基础设施,这与该工具的大多数其余部分使用的不同。从那个 GitHub 问题中的其他 cmets 来看,这个问题可能还没有完全解决。 DotNetCoreCLI 任务也可能没有为自定义命令设置身份验证。尝试添加 NuGetAuthenticate 任务,然后添加脚本任务(例如 PowerShell)以运行 dotnet
  • @JonathanMyers 你是对的。运行dotnet list package 之前的任务- task: NuGetAuthenticate@0 完成这项工作。拜托,你能写成回复,所以我会接受。

标签: azure-devops nuget azure-pipelines azure-artifacts dotnet-cli


【解决方案1】:

我找到了解决方法。当我删除 nuget.config 并明确添加源时,它成功了。

- script: |
      del nuget.config
      nuget sources add -name "Source1" -source https://pkgs.dev.azure.com/...../nuget/v3/index.json -username anything -password %SYSTEM_ACCESSTOKEN%
      nuget sources add -name "Source2" -source https://pkgs.dev.azure.com/....../nuget/v3/index.json -username anything -password %SYSTEM_ACCESSTOKEN%
    enabled: true
    env:
      SYSTEM_ACCESSTOKEN: $(System.AccessToken)
    displayName: Add NuGet source

但是,我想知道是否还有其他方法,因为这对我来说感觉很奇怪。

正如 Jonathan Myers 建议的那样,我使用了- task: NuGetAuthenticate@0,它几乎可以工作。几乎是因为在分析我得到的第一个项目时:

error: Problem starting the plugin 'C:\Users\VssAdministrator\.nuget\plugins\netcore\CredentialProvider.Microsoft\CredentialProvider.Microsoft.dll'. Plugin 'CredentialProvider.Microsoft' failed within 5.068 seconds with exit code -1.
error: Response status code does not indicate success: 401 (Unauthorized).

我找到了这个topic on Developer Community 并通读了一遍,但我仍在努力解决这个问题。

【讨论】:

  • 对于面临同样问题的人,我在尝试遵循NuGetAuthenticate@0 方法时遇到了同样的错误。通过将我之前安装 NuGet 客户端的步骤从版本5.4.0 更改为5.5.1 解决了这个问题。这似乎是credential provider 问题与来源无关。供参考:github.com/microsoft/artifacts-credprovider/issues/91
  • 我今天尝试了你的解决方案,我想更新你的访问令牌:使用 Windows 映像,通过%ACCESS_TOKEN% 使用访问令牌不起作用,但我可以使用$(System.AccessToken) 成功了!
猜你喜欢
  • 2023-03-26
  • 2021-03-22
  • 2022-11-23
  • 1970-01-01
  • 1970-01-01
  • 2022-08-16
  • 1970-01-01
  • 2018-10-29
  • 2021-05-25
相关资源
最近更新 更多