我有一个部署到多个环境的Service Fabric应用程序,每个环境都由一个Application xml元素定义,这是一种复杂的类型。在此Application元素中有一个参数列表,我想对这些参数应用XDT转换。
目标xml如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/SimFabric" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="Parameter1" Value="" key="key1"/>
<Parameter Name="Parameter2" Value="" key="key2"/>
</Parameters>
</Application>我要粘贴的Web.*.config采用以下形式:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<configSections>
<section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
</configSections>
<appSettings>
<add xdt:Transform="Replace" xdt:Locator="Match(key)" key="key1" value="value1" />
<add xdt:Transform="Replace" xdt:Locator="Match(key)" key="key2" value="value2" />
</appSettings>
</configuration>是否可以使用XDT转换将第二个文件中的值放在第一个文件中?
发布于 2020-07-15 14:29:19
XDT转换适用于每个XML文件。您可以测试此here
来源:
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Name="fabric:/SimFabric" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="Parameter1" Value="" />
<Parameter Name="Parameter2" Value="" />
</Parameters>
</Application>XDT变换:
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/SimFabric" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter xdt:Transform="Replace" xdt:Locator="Match(Name)" Name="Parameter1" Value="Value1" />
<Parameter xdt:Transform="Replace" xdt:Locator="Match(Name)" Name="Parameter2" Value="Value2" />
</Parameters>
</Application>结果:
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/SimFabric" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="Parameter1" Value="Value1" />
<Parameter Name="Parameter2" Value="Value2" />
</Parameters>
</Application>https://stackoverflow.com/questions/62900473
复制相似问题