8

我正在使用通过 VS2010 提供的 web.config 转换。在这种情况下,我想知道在转换过程中是否可以用另一个元素“包围”一个元素。这是一个例子:

默认 web.config 包含:

<configuration>
  <system.web>
   ....
  </system.web>
</configuration>

我的转换文件应该包含

<configuration>
  <location inheritInChildApplications="false">
    <system.web>
    ...
    </system.web>
  </location>
</configuration>

所以基本上我想用 location 元素“包装” system.web 元素。我唯一的想法是做一个转换,以便我在之前和之后插入:

<location inheritInChildApplications="false" 
          xdt:Transform="InsertBefore(/configuration/system.web)">
</location xdt:Transform="InsertAfter(/configuration/system.web)">

但是根据VS,关闭位置元素不是有效的xml(我猜是因为Transform属性)。只是在 system.web 之前插入一个自动关闭的位置元素也无济于事,因为生成的 system.web 仍然没有被“包围”。

4

2 回答 2

2

目前无法使用 web.config 转换来执行此操作,但如果您编写自定义转换,它确实应该是可行的......有一个关于如何编写自定义转换的文档更新,但还没有现在出来...

我会尽快发布它...

于 2010-12-17T18:10:55.040 回答
2

如果您在 webconfig 中添加一个空的位置标签,您希望它是无效的。

然后,您可以将其放入您的转换文件中与另一个相同的位置:

<location xdt:Locator="XPath(some xpath expression)" 
          inheritChildApplications="false" 
          xdt:Transform="SetAttributes(inheritChildApplications)">

还有结束标签等等。

于 2013-01-29T01:07:54.697 回答