Web.config transforms - surrounding elements

左心房为你撑大大i 提交于 2019-12-14 03:45:11

问题


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:

default web.config contains:

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

My transformed file should contain

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

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)">

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'.


回答1:


Currently it won't be possible to do this using web.config transformation, but it indeed should be feasible if you wrote a custom transform... There is a documentation update being worked on on how to write custom transforms but it is not yet out now...

I will post it as soon as it is available...




回答2:


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)">

with the closing tag too and all that.



来源:https://stackoverflow.com/questions/4466161/web-config-transforms-surrounding-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!