Web.config转换-周围的元素 [英] Web.config transforms - surrounding elements

查看:61
本文介绍了Web.config转换-周围的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用通过VS2010提供的web.config转换.在这种情况下,我想知道是否有可能在转换过程中将一个元素与另一个元素包围".这是一个示例:

I am using the web.config transforms available via VS2010. In this one case I'm wondering if it possible to 'surround' an element with another during transformation. Here is an example:

默认的web.config包含:

default web.config contains:

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

我的转换文件应包含

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

所以从本质上讲,我想将system.web元素与location元素包装在一起".我唯一的想法是进行转换,这样我就可以像这样插入前后:

So essentially I want to 'wrap' the system.web element with a location element. My only thought was to do a transform so that I inserted before and after like:

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

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

But the closing location element isn't valid xml according to VS (I'm guessing because of the Transform attribute). Just inserting a self-closing location element before system.web doesn't help either because the resulting system.web is still not 'surrounded'.

推荐答案

如果在Webconfig中添加一个空位置标记,则该标记将无效.

If you add an empty location tag in your webconfig where you would like it to be it will have no effect.

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

You can then put this in your transform file in the same location as the other one:

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

也带有结束标记.

这篇关于Web.config转换-周围的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆