如何在一个 web.config 元素上应用两种不同的转换?
在我的 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 转换语法的预期用途。
From my VS2010 deployment project I would like to apply two different transformations to two different attributes of one element in my web.config. Consider the following web.config snippet:
<exampleElement attr1="false" attr2="false" attr3="true" attr4="~/" attr5="false">
<supportedLanguages>
<!-- Some more elements here -->
</supportedLanguages>
</exampleElement>
Now how can I change attribute 'attr1' and remove attribute 'attr5' in the transformed web.config? I know how to perform the individual transformations:
<exampleElement attr1="true" xdt:Transform="SetAttributes(attr1)"></exampleElement>
and:
<exampleElement xdt:Transform="RemoveAttributes(attr5)"></exampleElement>
But I don't know how to combine these transforms. Anybody?
EDIT:
Can't answer my own question yet, but the solution seems to be:
It seems that it is possible to repeat the same element with different transformations, like so:
<?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>
As said, this seems to work, but I'm not sure whether this is the intended use of the web.config transformation syntax.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Nick Nieslanik 所证实的那样,这是通过使用不同的转换重复相同的元素来完成的,如下所示:
As Nick Nieslanik confirmed this is done by repeating the same element with different transformations, like so:
我正在使用 XmlPreprocess 工具 进行配置文件转换和处理操纵。它针对多种环境使用一个映射文件。您可以通过Excel编辑映射文件。它非常容易使用。
您可以使用 xmlpreprocess 更新配置文件,并使用配置(调试、开发、生产...)作为不同设置的参数...
I'm using XmlPreprocess tool for config files transformations & manipulation. It is using one mapping file for multiple environments. You can edit mapping file by Excel. It is very easy to use.
You can update your config files with xmlpreprocess and use configuration (debug, dev, prod,...) as a parameter for the different setup...