有没有办法做一个“替换或插入"?使用 web.config 转换? [英] Is there any way to do a "Replace Or Insert" using web.config transformation?
问题描述
我正在使用 web.config 转换,如下文所述,以便为不同的环境生成配置.
I'm using web.config transformation as described in the below post in order to generate configs for different environments.
http://vishaljoshi.blogspot.com/2009/03/web-deployment-webconfig-transformation_23.html
我可以通过匹配键来进行替换"转换,例如
I can do a "Replace" transformation by matching on the key, e.g.
<add key="Environment" value="Live" xdt:Transform="Replace" xdt:Locator="Match(key)" />
我可以做插入",例如
<add key="UseLivePaymentService" value="true" xdt:Transform="Insert" />
但我真正觉得有用的是 ReplaceOrInsert 转换,因为我不能总是依赖具有/不具有特定键的原始配置文件.
But what I would really find useful is a ReplaceOrInsert transformation, as I can't always rely on the original config file having/not having a certain key.
有没有办法做到这一点?
Is there any way to do this?
推荐答案
我找到了一种廉价的解决方法.如果您有很多需要替换或插入"的元素,它就不是很漂亮,也不会很好地工作.
I found a cheap workaround. It ain't pretty and won't work very well if you have a lot of elements that needs to be "Replace Or Insert".
先删除",然后再插入后|插入前".
Do a "Remove" and then an "InsertAfter|InsertBefore".
例如
<authorization xdt:Transform="Remove" />
<authorization xdt:Transform="InsertAfter(/configuration/system.web/authentication)">
<deny users="?"/>
<allow users="*"/>
</authorization>
这篇关于有没有办法做一个“替换或插入"?使用 web.config 转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!