Web.Release.config使用小技巧

来源:互联网 发布:rgb颜色渐变算法 c 编辑:程序博客网 时间:2024/06/05 14:36

开发asp.net应用程序的时候,通常debug和release的配置是不同的。多数开发人员都是直接发布web,然后手动修改配置文件web.config。

VS中提供了区分debug和release版本的配置方法,展开web.config,就能看到web.debug.config和web.release.config两个文件。
这里写图片描述

example:修改数据库链接

web.config中数据库链接字符串:

<connectionStrings>    <add name="debugConnection" connectionString="Server=XXX.XXX.XXX.1;Port=5432;User Id=*;Password=*;Database=*;" />  </connectionStrings>

web.release.config

<connectionStrings>    <add name="ReleaseConnection" connectionString="Server=XXX.XXX.XXX.2;Port=**;User Id=**;Password=**;Database=**;"         xdt:Locator="Match(name)" xdt:Transform="Replace" />

通过xdt:Locator定位需要替换或者删除的位置,xdt:Transform指定操作的方式(Replace or Remove).通过这样简单的设置,就可以实现debug和release使用不同的配置完了。

0 0