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

将NuGet包部署到内部Azure Artifacts源失败求助

排查Azure Artifacts NuGet包推送无报错但未入库问题

问题背景

搭建Azure Artifacts源用来部署团队的NuGet包,已经创建好源并连接了上游源。配置了main分支触发的YAML流水线,不管用上游源还是非上游源做还原和推送,流水线跑起来都没报错,但NuGet包就是没出现在任何源里。项目实际路径是\Service\Service\bin\Debug,下面是现有流水线配置和nuget.config内容:

当前配置

流水线YAML

trigger:
- main    

pool:
  vmImage: ubuntu-latest

variables:
  buildConfiguration: 'Release'

steps:
- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    feedsToUse: 'select'
- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'select'
    vstsFeed: '{InternalUpstreamFeedArtifact}'
- task: NuGetCommand@2
  inputs:
    command: 'pack'
    packagesToPack: '*.csproj'
    versioningScheme: 'off'
- task: NuGetCommand@2
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: '{ InternalUpstreamFeedArtifact }'

nuget.config文件

<?xml version="1.0" encoding="utf-8"?>
<configuration>
       <packageSources>
             <clear />
             <add key="TestFeed" value=https://pkgs.dev.azure.com/Company/Project/_packaging/TestFeed/nuget/v3/index.json />
       </packageSources>
</configuration>

排查与修复方向

1. Pack任务找不到项目,且生成的包没进 staging 目录

  • 项目在Service/Service路径下,但Pack任务里packagesToPack: '*.csproj'只会在流水线当前工作根目录找csproj文件,根本找不到目标项目。改成packagesToPack: 'Service/Service/*.csproj'或者**/*.csproj(如果只有这一个要打包的项目)。
  • NuGet Pack任务默认不会把生成的nupkg放到$(Build.ArtifactStagingDirectory),Push任务自然找不到包。必须给Pack任务加outputDirectory: '$(Build.ArtifactStagingDirectory)'参数,同时指定和变量一致的Release配置,修改后的Pack任务:
    - task: NuGetCommand@2
      inputs:
        command: 'pack'
        packagesToPack: 'Service/Service/*.csproj'
        versioningScheme: 'off'
        outputDirectory: '$(Build.ArtifactStagingDirectory)'
        buildProperties: 'Configuration=$(buildConfiguration)'
    

2. 冗余的Restore任务与Feed参数错误

流水线里同时跑了DotNetCoreCLI和NuGetCommand的Restore任务,完全没必要,留一个即可。另外Push任务里的publishVstsFeed: '{ InternalUpstreamFeedArtifact }'有多余空格,会导致Feed识别错误,赶紧去掉空格,确保和vstsFeed里的参数一致。

3. nuget.config格式问题

nuget.config里的value属性没加引号,不符合XML规范,改成:

<add key="TestFeed" value="https://pkgs.dev.azure.com/Company/Project/_packaging/TestFeed/nuget/v3/index.json" />

4. 权限验证

确认流水线使用的服务账号对目标Azure Artifacts源有推送权限(前往Feed的权限设置页面检查,至少需要Contributor权限)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 16:11:16