Asp.net 使用web.config转换在根元素上设置多个属性
在visual studio(web.config转换)中,我要执行一个转换,在根元素上添加两个属性。 一个属性有效(但不是多个属性)。 我可以在一个子元素上设置多个属性。 我尝试过SetAttributes,有没有指定属性的名称,运气都不好 想法 示例Asp.net 使用web.config转换在根元素上设置多个属性,asp.net,.net,web-config,web-deployment,web-config-transform,Asp.net,.net,Web Config,Web Deployment,Web Config Transform,在visual studio(web.config转换)中,我要执行一个转换,在根元素上添加两个属性。 一个属性有效(但不是多个属性)。 我可以在一个子元素上设置多个属性。 我尝试过SetAttributes,有没有指定属性的名称,运气都不好 想法 示例 <element xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="SetAttributes" attrOne="One
<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>
理想效果
<element attrOne="One" attrTwo="Two">
<children>
<child name="One" attrOne="One" attrTwo="Two" />
</children>
</element>
“element”部分实际上是web.config文件的自定义部分……如下所示:
<configuration>
... <element configSource="App_Data\element.config" />
...
此转换用于element.config文件(使用slow cheetah)
更新
这显然也不起作用:
<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>
但这确实:
<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>
一旦根元素上有超过1个属性,它就会失败文件
web.config
的文档元素就是
。在您的示例中,
可能是
的孩子。尝试:
<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>
您是否尝试过这样的文档转换,即通过将要设置的属性列表传递给
SetAttribute()
来同时设置多个属性
请参阅表格了解更多信息
具体来说:Transform=“SetAttributes(一个或多个属性名称的逗号分隔列表)”
抱歉,意思是说它本身不是web.config文件,但这显示了它的一个自定义部分。然而有趣的是,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>