我正在尝试在发布阶段从XML转换文件转换.config文件。我正在使用标准的文件转换任务。我向我的工件添加了一个transform.xml文件(未链接到合法发行版),并且可以看到它。当我尝试使用它时,我得到以下System.Debug输出:
2020-05-01T17:25:21.6011428Z Processing substitution for xml node : connectionStrings
2020-05-01T17:25:21.6022113Z ##[debug]Provided node is empty or a comment.
2020-05-01T17:25:21.6025339Z ##[debug]Provided node is empty or a comment.
2020-05-01T17:25:21.6027416Z ##[debug]Unable to find node with tag 'configSections' in provided xml file.
2020-05-01T17:25:21.6028615Z Skipped Updating file: xxxxxxxx.config
transform.xml文件的内容如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings xdt:Transform="Replace">
<add name="XX" connectionString="user id=XXX;password=XXXXX;data source=XXXXXXXX"/>
</connectionStrings>
</configuration>
Azure Devops版本-文件转换-提供的节点为空或注释
我无法通过以下配置文件和您的转换文件重现此问题:
配置文件web.config(XML transformation example中的代码示例:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\\MSDB;DbFilename=aspcore-local.mdf;" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<authentication mode="None" />
<compilation targetFramework="4.5" debug="true" />
</system.web>
</configuration>
然后使用转换文件的内容创建Web.test.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings xdt:Transform="Replace">
<add name="XX" connectionString="user id=XXX;password=XXXXX;data source=XXXXXXXX"/>
</connectionStrings>
</configuration>
注意:
XML转换将在名为*.Release.config
或*.<stage>.config
的转换配置文件的*。config文件上运行。因此,我们不能使用transform.xml
而不是*.<stage>.config
。
作为测试结果,替换了connectionStrings
中的web.config
字符串:
请查看文档File transforms and variable substitution reference了解更多详细信息。
希望这会有所帮助。