You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps中NuGetCommand@2无法加载Azure Artifacts源服务索引

解决Azure DevOps项目级NuGet源拉取包时的NU1301错误

问题核心

你的nuget.config配置了项目级NuGet源URL(包含[PROJECT_NAME]),但NuGetCommand@2任务通过vstsFeed参数生成的源URL缺少项目名称,导致NuGetAuthenticate@1注入的凭据无法匹配目标源,最终触发NU1301错误。

解决方案

方案1:直接使用自定义nuget.config文件

修改NuGetCommand@2任务,放弃vstsFeed参数,指定使用你本地的nuget.config,确保源URL完全匹配:

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'config'
    nugetConfigPath: 'nuget.config' # 替换为你的nuget.config实际路径

方案2:修正vstsFeed参数为项目级Feed标识

Azure DevOps项目级Feed的正确标识格式是[PROJECT_NAME]/[FEED_NAME],而非单独的[FEED_NAME],更新NuGetCommand@2的参数:

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    vstsFeed: '[PROJECT_NAME]/[FEED_NAME]' # 补充项目名称前缀

方案3:让NuGetAuthenticate关联自定义nuget.config

如果需要保留自定义配置,在NuGetAuthenticate@1任务中指定你的nuget.config路径,确保凭据注入到正确的源:

- task: NuGetAuthenticate@1
  inputs:
    nugetConfigPath: 'nuget.config' # 指定配置文件,确保凭据匹配项目级源

额外验证

  • 确认构建服务账号的协作者角色是分配给目标项目级Feed,而非组织级Feed
  • 查看构建日志,确认NuGetCommand@2使用的源URL包含[PROJECT_NAME],与nuget.config配置一致

内容的提问来源于stack exchange,提问作者christophe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 04:45:11