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

发布于 2024-12-28 02:33:15 字数 1296 浏览 5 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝影如岚 2025-01-04 02:33:15

正如 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>

As Nick Nieslanik confirmed this is done by repeating 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>
川水往事 2025-01-04 02:33:15

我正在使用 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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文