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

如何通过GitHub Action变量替换修改XML连接字符串节点值

精准修改XML中connectionString属性的GitHub Action配置方法
  • 问题根源:你之前的配置connectionStrings.add会直接替换整个<add>节点,导致XML结构错乱,没法精准修改connectionString属性。
  • 正确的变量定位格式:针对XML的属性,需要用元素路径[@属性筛选]@目标属性的格式来精准定位。对于你的场景,要定位name="DefaultConnectionString"的<add>节点下的connectionString属性,变量名应该写成:
    connectionStrings.add[name='DefaultConnectionString']@connectionString
    
  • 修改后的完整Action配置:
    - uses: microsoft/variable-substitution@v1 
      with:
          files: './Website/cnfgConnection.config'
      env:
          connectionStrings.add[name='DefaultConnectionString']@connectionString: "Data Source=prod.server.com;Initial Catalog=test;User ID=prod_tester;Password=xxxxxx"
    
  • 效果说明:执行这个Action后,你的cnfgConnection.config里的<add>节点会保留name和providerName属性,只有connectionString的值会被替换成你指定的生产环境字符串。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 00:24:17