【问题标题】:How to apply two different transformations on one web.config element?如何在一个 web.config 元素上应用两种不同的转换?
【发布时间】:2012-02-15 02:07:48
【问题描述】:

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

<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 转换语法的预期用途。

【问题讨论】:

  • 这是正确的,因为我一直在使用 XmlTransforms。我相信你已经回答了这个问题:)

标签: visual-studio-2010 msbuild web-config element transform


【解决方案1】:

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

【讨论】:

  • 这个问题是关于对一个元素的不同属性应用不同的转换,情况略有不同。
【解决方案2】:

我使用XmlPreprocess tool 进行配置文件转换和操作。它为多个环境使用一个映射文件。您可以通过 Excel 编辑映射文件。这是非常容易使用。 您可以使用 xmlpreprocess 更新配置文件,并使用配置(调试、开发、产品...)作为不同设置的参数...

【讨论】:

  • 看起来确实是一种非常强大的转换方式,但对于我现在的需求来说可能有点矫枉过正。
猜你喜欢
  • 1970-01-01
  • 2011-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-07
  • 2012-07-28
  • 2011-09-30
  • 2011-05-26
相关资源
最近更新 更多