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中使用VSCommands插件在大括号尾部显示方法或过程名字
- visual studio中快速定位打开的文件所处的树形路径
- Visual Studio中使用正则表达式替换
- Visual Studio的browser link
- Visual Studio中 sln 和 suo 文件
- Visual Studio 调试方法
- Visual Studio 编译中活动平台AnyCPU
- Visual Studio代码缩略图
- 使用Visual Studio对项目进行远程调试
- Visual Studio使用Git进行源代码管理
- 实用的Visual Studio插件
- visual studio怎么连接数据库(使用Visual Studio Code连接MySql数据库并进行查询)
- Visual Studio 自动添加头部注释
- 创建自己的Visual Studio工程模板
- vscode react插件(基于visual studio code + react 开发环境搭建过程)
- 使用Visual Studio为WebAPI生成帮助文档
- 做网红真的很能赚钱吗(做网红真的很能赚钱吗)
- 10句英语常用(英语常用900句)
- 爱情能当饭吃吗(爱情能当饭吃吗说说)
- 白T恤穿法(白t恤)
- 你怎么忘了是说先爱我(你怎么忘了如何爱我)
- 做技术难吗(技术难不难)
热门推荐
- mysql日常运维(MySQL从库维护经验分享)
- dedecms标签怎么用(dedecms 添加字段后软件列表页无法调用软件大小问题的解决方法)
- docker快速配置redis集群(基于docker搭建redis集群的方法)
- python常见知识点整理(Python基础知识点 初识Python.md)
- JS匿名函数的用法
- apache安全配置使用教程(正确配置与维护Apache安全性设置方法)
- serv-u服务器安装(Serv-U搭建FTP服务器教程之建立登录用户和密码)
- sqlserver 查询锁(sqlserver:查询锁住sql以及解锁方法)
- jQuery邮箱自动补全
- nodejs请求页面(node.js+postman实现模拟HTTP服务器与客户端交互)