如何删除使用配置转换的的ConnectionString [英] How to remove a ConnectionString using Config Transformations

查看:213
本文介绍了如何删除使用配置转换的的ConnectionString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个的ConnectionStrings一个Web.config

I have a Web.config with several ConnectionStrings

<connectionStrings>
    <add name="connStr1" connectionString="...
    <add name="ConnStr2" connectionString="...
    <add name="connStr3" connectionString="...

有没有使用配置转换来删除特定的ConnectionString的方法吗?是这样的:

Is there a way using config transformations to remove a specific connectionstring? Something Like:

<connectionStrings>
    <xdt:Remove connStr2?

显然接近正确的语法没有在那里,但你明白我的意思......

Obviously no where near the correct syntax, but you get my drift...

推荐答案

MSDN文档关于这个问题的:

<configuration xmlns:xdt="...">
  <connectionStrings>
    <add xdt:Transform="Remove" />
  </connectionStrings>
</configuration>

变换=删除就是你要寻找的法宝。还有一个变换=removeall过,你也许可以结合使用具有特定加载(S)。

The Transform="Remove" is the magic you're looking for. There is also a Transform="RemoveAll" which you might be able to use in conjunction with a specific add(s).

修改

在第二个想你也能够在 定位 的属性与删除上面来限制哪些元素你真的想删除定义的。

On second thought you may also be able to combine the Locator attribute with the Remove defined above to limit which elements you actually want to delete.

更明确:

<configuration xmlns:xdt="...">
  <connectionStrings>
    <add xdt:Transform="Remove" xdt:Locator="XPath(configuration/connectionStrings[@name='ConnStr2'])" />
  </connectionStrings>
</configuration>

或类似的应该工作。

Or similar should work.

这篇关于如何删除使用配置转换的的ConnectionString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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