Azure DevOps Pipeline NuGet推送失败:NuGetProtocolVersionNotSupportedException
解决Azure DevOps Pipeline NuGet推送V2协议不支持问题
问题分析
多个长期稳定运行的流水线突然在PublishNuGetPackages步骤报错,提示提供的URL是NuGet V2 URL,而当前命令仅支持V3协议。这大概率是微软对Azure Artifacts的协议支持或NuGet任务默认配置进行了变更,导致原有任务逻辑不再适配。
解决方案
1. 改用dotnet命令推送(推荐)
放弃NuGetCommand@2,改用dotnet nuget push配合NuGetAuthenticate@1完成认证,dotnet工具对V3协议的支持更稳定,且能自动适配Azure Artifacts的源:
- task: NuGetAuthenticate@1 displayName: 'NuGet Authenticate' condition: and(succeeded(), eq(variables.isPullRequest, 'false')) - task: CmdLine@2 displayName: 'Publish NuGet Packages via dotnet' condition: and(succeeded(), eq(variables.isPullRequest, 'false')) inputs: script: | dotnet nuget push "$(System.DefaultWorkingDirectory)/**/*.nupkg;!$(System.DefaultWorkingDirectory)/**/*.symbols.nupkg" --source "https://pkgs.dev.azure.com/{你的组织名}/{你的项目名}/_packaging/{你的Feed名}/nuget/v3/index.json" --api-key azdo --skip-duplicate
注意替换URL中的组织、项目、Feed名称,
--skip-duplicate对应原配置的allowPackageConflicts: true
2. 指定NuGet工具版本为最新稳定版
在原NuGetCommand@2任务中强制指定最新版NuGet工具,旧版本工具可能无法正确识别Azure Artifacts的V3源:
- task: NuGetCommand@2 displayName: 'Publish NuGet Packages' condition: and(succeeded(), eq(variables.isPullRequest, 'false')) inputs: command: 'push' packagesToPush: '$(System.DefaultWorkingDirectory)/**/*.nupkg;!$(System.DefaultWorkingDirectory)/**/*.symbols.nupkg' nuGetFeedType: 'internal' publishVstsFeed: '{guid}/{guid}' allowPackageConflicts: true nuGetVersion: 'latest' # 新增:指定最新NuGet工具版本
3. 手动指定V3源URL
如果上述方法无效,可手动使用V3格式的源URL,通过服务连接完成推送:
- 在Azure DevOps中创建对应Feed的服务连接(类型为NuGet),填入V3源URL:
https://pkgs.dev.azure.com/{org}/{proj}/_packaging/{feed}/nuget/v3/index.json - 修改YAML任务:
- task: NuGetCommand@2 displayName: 'Publish NuGet Packages' condition: and(succeeded(), eq(variables.isPullRequest, 'false')) inputs: command: 'push' packagesToPush: '$(System.DefaultWorkingDirectory)/**/*.nupkg;!$(System.DefaultWorkingDirectory)/**/*.symbols.nupkg' nuGetFeedType: 'external' publishFeedCredentials: '你的服务连接名称' allowPackageConflicts: true
内容的提问来源于stack exchange,提问作者Ryan Thomas
相关产品推荐
相关产品推荐

