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

GitHub Actions添加Azure Artifact Feed遇包还原问题求助

解决GitHub Actions中Azure Artifacts NuGet源配置问题

针对你遇到的几个核心问题,逐一给出落地解决方案:

1. 解决「源名称重复」错误

执行添加源操作前,先删除同名源避免冲突,即使源不存在也不会中断流程:

- name: Remove existing nuget source if exists
  run: dotnet nuget remove source ${{ env.nuget_feed_name }} --non-interactive || true
- name: Add custom nuget source
  run: dotnet nuget add source ${{ env.nuget_feed_source }} --name ${{ env.nuget_feed_name }} --username az --password ${{ secrets.ARTIFACTKEY }} --store-password-in-clear-text

2. 修复「无法加载服务索引」(NU1301)

  • 确认nuget_feed_source的URL格式正确,Azure Artifacts标准源URL应为:
    https://pkgs.dev.azure.com/<组织名>/<项目名>/_packaging/<Feed名>/nuget/v3/index.json
    
  • 检查secrets.ARTIFACTKEY是否为拥有**「Packaging (Read)」权限**的Azure DevOps个人访问令牌(PAT),权限缺失会导致无法访问源索引。

3. 确保dotnet restore使用自定义源

方式一:显式指定还原源

在dotnet restore命令中直接指定所需源,确保依赖搜索路径正确:

- name: Restore
  run: dotnet restore "${{ env.WORKING_DIRECTORY }}" --source ${{ env.nuget_feed_source }} --source https://api.nuget.org/v3/index.json

方式二:动态生成专属nuget.config

生成独立的配置文件清空默认源,避免环境默认配置干扰:

- name: Generate nuget.config
  run: |
    cat > nuget.config << EOF
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <clear />
        <add key="${{ env.nuget_feed_name }}" value="${{ env.nuget_feed_source }}" />
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
      </packageSources>
      <packageSourceCredentials>
        <${{ env.nuget_feed_name }}>
          <add key="Username" value="az" />
          <add key="ClearTextPassword" value="${{ secrets.ARTIFACTKEY }}" />
        </${{ env.nuget_feed_name }}>
      </packageSourceCredentials>
    </configuration>
    EOF
  working-directory: ${{ env.WORKING_DIRECTORY }}

之后执行还原会自动读取该配置:

- name: Restore
  run: dotnet restore "${{ env.WORKING_DIRECTORY }}"

4. 验证源配置有效性

在还原前添加步骤,确认自定义源已正确加载:

- name: List nuget sources
  run: dotnet nuget list source

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.26 07:45:33