Web.Release.config 和 Web.Debug.config
Web.Release.config 和 Web.Debug.config
Web.Release.config 和 Web.Debug.config通过在web.release.config或web.debug.config中按指定的格式查找和替换节点内容,可以实现web.config按生成环境的不同生成不同的版本,方便调试和发布。
在开发asp.net应用程序时,往往想在debug和release环境下使用不同的配置,而web.config文件却只有一个,我们可以在Web.Debug.config中写下debug环境下的配置,然后在web.release.config中写下release环境下特有的配置。
一、Web.Release.config 和 Web.Debug.config实例
1、Web.Release.config 的配置文件
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
-->
<connectionStrings>
<add name="AppConnection"
connectionString="发布环境连接字符串"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
</configuration>
2、Web.Debug.config 的配置文件
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
-->
<connectionStrings>
<add name="AppConnection"
connectionString="测试环境连接字符串"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
</configuration>
3、Web.config 的配置文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="AppConnection" connectionString="默认连接字符串"/>
<add name="TestCommon" connectionString="公共使用的连接字符串"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
4、发布 后Web.config 的配置文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<connectionStrings> <!--注意这里的字符串变了,变成了release配置文件中的字符串 -->
<add name="AppConnection" connectionString="发布环境连接字符串"/>
<add name="TestCommon" connectionString="公共使用的连接字符串"/>
</connectionStrings>
<system.web>
<compilation targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
二、配置说明
xdt:Transform="SetAttributes" xdt:Locator="Match(name)" 的意思
把Web.config中connectionStrings对应name为AppConnection的节点属性替换。
1、locator属性
1)Match
用匹配的属性名去替换Web.config中的属性值
例如:Web.config中找到匹配name为Norhwind的节点值替换为相应配置文件的值。
<connectionStrings>
<add name="Northwind" connectionString="connection string detail"
providerName="System.Data.SqlClient"
xdt:Transform="Replace"
xdt:Locator="Match(name)" />
</connectionStrings>
2)Condition
基于XPath,在Locator可以用表达式判断匹配
<connectionStrings>
<add name="Northwind"
connectionString="connection string detail"
providerName="System.Data.SqlClient"
xdt:Transform="Replace"
xdt:Locator="Condition(@name=’Northwind or @providerName=' System.Data.SqlClient')" />
</connectionStrings>
2、 Transform 属性
1)Replace 表示所有匹配的节点都是替换
2)Remove 删除第一匹配的元素。
3)RemoveAll
4)Insert 插入从父节点中插入
例如:authorization中插入<deny users="*" />
<authorization>
<deny users="*" xdt:Transform="Insert"/>
</authorization>
5)SetAttributes 设置属性值
- 改变Visual Studio的主题
- Visual Studio 编译中活动平台AnyCPU
- 实用的Visual Studio插件
- Visual Studio中使用正则表达式替换
- 关闭visual studio 的实时调试
- Visual Studio代码缩略图
- Visual studio中使用VSCommands插件在大括号尾部显示方法或过程名字
- 使用Visual Studio为WebAPI生成帮助文档
- 介绍几个Visual Studio 调试技巧
- vscode react插件(基于visual studio code + react 开发环境搭建过程)
- Visual Studio 调试方法
- Visual Studio的browser link
- visual studio中快速定位打开的文件所处的树形路径
- 使用Visual Studio对项目进行远程调试
- 创建自己的Visual Studio工程模板
- Visual Studio中 sln 和 suo 文件
- 素人恋爱综艺火药味十足 男生为赢得芳心集体扯头花,真是出好戏(素人恋爱综艺火药味十足)
- 《囧妈》为何受抵制 春节七部影片撤档背后的责任与博弈(囧妈为何受抵制)
- 提醒 2019年起河南驾考要开设科目五 官方回应来了(2019年起河南驾考要开设科目五)
- 省 市书法家协会 送万福进万家 活动走进禹州美丽乡村(省市书法家协会)
- 点赞 禹州苌庄正式撤乡建镇 未来发展不可估量(禹州苌庄正式撤乡建镇)
- 它荣获 中国生态魅力镇 称号 就在咱们禹州,一起来看看(中国生态魅力镇)
热门推荐
- 如何看http状态码(10个常见的HTTP状态码详解)
- html标签的嵌套规则
- 宝塔面板一键部署教程(使用宝塔面板负载均衡插件的心得和解决的方法)
- css3实现3d效果教程(CSS3实现简易版的刮刮乐效果)
- dede织梦的后台如何调整和使用(dedecms织梦模板去掉文档内链自动连接关键词的下划线)
- python控制流实例(如何用C代码给Python写扩展库Cython)
- js统计文本框剩余可输入字数
- mysql索引的比较规则(MySQL的Flush-List和脏页的落盘机制)
- zabbix sender能否发送告警数据(python3实现zabbix告警推送钉钉的示例)
- mysql索引的类型和方法(MySQL覆盖索引的使用示例)