繁体   English   中英

如何在一个web.config元素上应用两个不同的转换?

[英]How to apply two different transformations on one web.config element?

从我的VS2010部署项目中,我想对web.config中的一个元素的两个不同属性应用两种不同的转换。 请考虑以下web.config片段:

<exampleElement attr1="false" attr2="false" attr3="true" attr4="~/" attr5="false">
  <supportedLanguages>
    <!-- Some more elements here -->
  </supportedLanguages>
</exampleElement>

现在我如何在转换后的web.config中更改属性'attr1'并删除属性'attr5'? 我知道如何执行单个转换:

<exampleElement attr1="true" xdt:Transform="SetAttributes(attr1)"></exampleElement>

和:

<exampleElement xdt:Transform="RemoveAttributes(attr5)"></exampleElement>

但我不知道如何结合这些变换。 任何人?

编辑:

无法回答我自己的问题,但解决方案似乎是:

似乎可以使用不同的转换重复相同的元素,如下所示:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <exampleElement attr1="true" xdt:Transform="SetAttributes(attr1)"></exampleElement>
    <exampleElement xdt:Transform="RemoveAttributes(attr5)"></exampleElement>
</configuration>

如上所述,这似乎有效,但我不确定这是否是web.config转换语法的预期用途。

正如Nick Nieslanik所证实的那样,通过重复使用不同变换的相同元素来完成,如下所示:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <exampleElement attr1="true" xdt:Transform="SetAttributes(attr1)"></exampleElement>
    <exampleElement xdt:Transform="RemoveAttributes(attr5)"></exampleElement>
</configuration>

我正在使用XmlPreprocess工具进行配置文件转换和操作。 它使用一个映射文件用于多个环境。 您可以通过Excel编辑映射文件。 这是非常容易使用。 您可以使用xmlpreprocess更新配置文件,并使用配置(debug,dev,prod,...)作为不同设置的参数...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM