微软的MSDeploy提供了web.config transform方式,提供发布时对web.config的变换能力以应对不同模式的部署。VS2010创建ASP.NET项目的时候就默认提供了debug版和release版的web.config。详细可以参考MSDN。
而还有一些场景是也需要在部署的时候变更web.config内容,但是需要通过外部(例如安装程序)指定需要变换的参数。这就要用到了web.config的参数化。这部分内容似乎MSDN上没有详细讲(或者我没找到)。
在这里找到了一些相关的说明(请自备FQ工具)。
摘要如下:
Step 1: 创建Parameters.xml,设置希望在部署阶段变换的参数。
没找到对应的schema,手写起来有点麻烦,好歹我这一次需要参数化的内容不多。首先给出一个参考(来自上述博文)
<?xml version="1.0" encoding="utf-8" ?>
<parameters >
<parameter name="Log Folder Location" description="Please provide a shared location where the app can write log files to" defaultValue="\\Logs\MvcApp\Logs\" tags="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='LogFolder']/@value" />
</parameter>
<parameter name="WCF Service1 Endpoint Address" description="Please provide the Endpoint address for Service1 that this MVC App needs to call" defaultValue="http://localhost:61938/Service1.svc" tags="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="//system.serviceModel/client/endpoint/@address" />
</parameter>
</parameters>
<parameters >
<parameter name="Log Folder Location" description="Please provide a shared location where the app can write log files to" defaultValue="\\Logs\MvcApp\Logs\" tags="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='LogFolder']/@value" />
</parameter>
<parameter name="WCF Service1 Endpoint Address" description="Please provide the Endpoint address for Service1 that this MVC App needs to call" defaultValue="http://localhost:61938/Service1.svc" tags="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="//system.serviceModel/client/endpoint/@address" />
</parameter>
</parameters>