【发布时间】: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