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

Ubuntu24.04下用DotNetCoreCLI@2替代NuGetCommand@2推送Azure DevOps私有源的问题

解决方案

1. 优先使用DotNetCoreCLI@2原生push命令

直接利用DotNetCoreCLI@2的push命令类型,它会自动处理Azure DevOps私有源的身份验证与URL解析,无需手动拼接,同时通过--skip-duplicate参数实现原allowPackageConflicts: true的功能。

示例流水线配置:

- task: DotNetCoreCLI@2
  displayName: '推送NuGet包到Azure DevOps私有源'
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: '你的私有源固定ID/名称' # 替换为Azure DevOps Artifacts中你的Feed固定ID或名称
    arguments: '--skip-duplicate'

关键细节:

  • publishVstsFeed填写的私有源固定ID可在Azure DevOps的Artifacts Feed设置中获取(路径:Artifacts → 目标Feed → 设置 → 常规 → Feed ID),该ID不会随流水线运行变化
  • --skip-duplicate参数会自动跳过已存在于私有源中的包,完全等价于旧任务的allowPackageConflicts: true

2. 自定义NuGet命令的替代方案

若必须使用custom命令调用nuget push,可通过Azure DevOps预定义变量拼接固定的私有源URL,避免动态GUID的问题:

- task: DotNetCoreCLI@2
  displayName: '自定义NuGet推送至私有源'
  inputs:
    command: 'custom'
    customCommand: 'push'
    arguments: '$(Build.ArtifactStagingDirectory)/**/*.nupkg --source "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_packaging/你的私有源固定ID/nuget/v3/index.json" --api-key azdo --skip-duplicate'

关键细节:

  • --api-key azdo是Azure DevOps私有源的固定验证标识,流水线会自动使用当前运行上下文的权限进行认证
  • URL中的私有源ID为固定值,不会随每次运行变化

3. 批量推送多包的实现

无论是原生push还是自定义命令,都可通过通配符**/*.nupkg批量匹配所有NuGet包,用!前缀排除符号包(若无需推送)。如需更精细控制,可使用PowerShell脚本遍历推送:

- task: PowerShell@2
  displayName: '批量推送NuGet包'
  inputs:
    targetType: 'inline'
    script: |
      $packages = Get-ChildItem -Path $(Build.ArtifactStagingDirectory) -Filter *.nupkg -Recurse
      foreach ($package in $packages) {
        dotnet push $package.FullName --source "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_packaging/你的私有源固定ID/nuget/v3/index.json" --api-key azdo --skip-duplicate
      }

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 11:09:57