使用web.config转换在根元素上设置多个属性

Joh*_*ino 7 .net asp.net web-config web-deployment web-config-transform

在visual studio(web.config转换)中,我有一个我想要执行的转换,它在根元素上添加了两个属性.一个attrbute工作(但不是多个).我可以在子元素上设置多个属性.我已尝试使用和不指定属性名称的SetAttributes,没有运气.

想法?

    <element xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="SetAttributes" attrOne="One" attrTwo="Two">
      <children>
       <child name="One" xdt:Transform="SetAttributes" attrOne="One" attrTwo="Two" />
      </children>
    </element>
Run Code Online (Sandbox Code Playgroud)

期望的效果

    <element attrOne="One" attrTwo="Two">
      <children>
       <child name="One" attrOne="One" attrTwo="Two" />
      </children>
    </element>
Run Code Online (Sandbox Code Playgroud)

"element"部分实际上是web.config文件的自定义部分......就像这样:

<configuration>

... <element configSource="App_Data\element.config" />
Run Code Online (Sandbox Code Playgroud)

这个转换意味着在element.config文件中使用(使用慢速猎豹)

更新 这显然不起作用:

<element xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="Replace" attrOne="One" attrTwo="Two">
  <children>
   <child name="One" attrOne="One" attrTwo="Two" />
  </children>
</element>
Run Code Online (Sandbox Code Playgroud)

但这样做:

<element xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="Replace" attrOne="One">
  <children>
   <child name="One" attrOne="One" attrTwo="Two" />
  </children>
</element>
Run Code Online (Sandbox Code Playgroud)

只要根元素上有多个属性,它就会失败

chr*_*_68 12

您是否尝试过这样的文档转换,通过传递要设置的属性列表来同时设置多个属性SetAttribute()

请参阅此处表单更多信息.

具体来说:Transform ="SetAttributes(一个或多个属性名称的逗号分隔列表)"

<element xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="SetAttributes(attrOne,attrTwo)" attrOne="One" attrTwo="Two">
  <children>
   <child name="One" xdt:Transform="SetAttributes(attrOne,attrTwo)" attrOne="One" attrTwo="Two" />
  </children>
</element>
Run Code Online (Sandbox Code Playgroud)


Fré*_*idi 0

文件的文档元素web.config<configuration>. 在您的示例中,<element>可能是 的子级<configuration>。尝试:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <element xdt:Transform="SetAttributes" attrOne="One" attrTwo="Two">
        <children>
            <child xdt:Transform="SetAttributes" name="One"
                   attrOne="One" attrTwo="Two" />
        </children>
    </element>
</configuration>
Run Code Online (Sandbox Code Playgroud)