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

Azure DevOps:NuGet.config无效问题排查与解决

问题:Azure DevOps流水线dotnet restore使用自定义NuGet源时XML格式错误

错误现象

本地解决方案依赖可正常加载,但流水线执行dotnet restore任务时抛出NuGet.Config无效XML的错误,具体报错信息:

C:\hostedtoolcache\windows\dotnet\sdk\6.0.407\NuGet.targets(649,5): error : NuGet.Config is not valid XML. Path: 'D:\a\1\Nuget\tempNuGet_325.config'. [D:\a\1\s\Helpers\Helpers.csproj]
C:\hostedtoolcache\windows\dotnet\sdk\6.0.407\NuGet.targets(649,5): error : The '$' character, hexadecimal value 0x24, cannot be included in a name. Line 1, position 273. [D:\a\1\s\Helpers\Helpers.csproj]

对应的出错YAML任务配置:

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    feedsToUse: 'select'
    vstsFeed: $(vstsFeed)

排查与解决过程

  • 临时缓解措施:将变量$(vstsFeed)替换为实际值后,问题暂时消失。该变量原本存储在DevOps库的变量组中。
  • 根因定位:最终发现是流水线YAML中未引用对应的变量组,导致$(vstsFeed)变量未被正确解析,直接以带$的字符串写入NuGet.Config,违反XML节点命名规则,触发格式错误。

修复后的可行配置

在包含dotnet restore任务的作业中添加变量组引用即可解决问题,示例如下(dotnet restore任务定义在builder.yml模板中):

- stage: Build
  displayName: Build and create artifacts
  jobs:
    - job: "Build"
      timeoutInMinutes: ${{variables.pipelineTimeout}}
      variables:
        - group: "Common_shared" # 引用存储vstsFeed变量的变量组
      pool:
        vmImage: ${{variables.vmImage}}
      steps:
        - template: "builder.yml"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 07:42:40