This is a mirror of official site: http://jasper-net.blogspot.com/

Web.config Transformation Syntax for Web Application Project Deployment

| Thursday, November 18, 2010
Web.config files typically include settings that have to be different depending on which environment the application is running in. For example, you might have to change a database connection string or disable debugging when you deploy a Web.config file. For Web application projects, ASP.NET provides tools that automate the process of changing (transforming) Web.config files when they are deployed. For each environment that you want to deploy to, you create a transform file that specifies only the differences between the original Web.config file and the deployed Web.config file for that environment.

A transform file is an XML file that specifies how the Web.config file should be changed when it is deployed. Transformation actions are specified by using XML attributes that are defined in the XML-Document-Transform namespace, which is mapped to the xdt prefix. The XML-Document-Transform namespace defines two attributes: Locator and Transform. The Locator attribute specifies the Web.config element or set of elements that you want to change in some way. The Transform attribute specifies what you want to do to the elements that the Locator attribute finds.

The following example shows the contents of a transform file that changes a connection string and replaces the customErrors element:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
 <connectionStrings>
   <add name="MyDB"
     connectionString="value for the deployed Web.config file"
     xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
 </connectionStrings>
 <system.web>
   <customErrors defaultRedirect="GenericError.htm"
     mode="RemoteOnly" xdt:Transform="Replace">
     <error statusCode="500" redirect="InternalError.htm"/>
   </customErrors>
 </system.web>
</configuration>
The root element of a transform file must specify the XML-Document-Transform namespace in its opening tag, as shown in the preceding example. The Locator and Transform elements themselves are not reproduced in the deployed Web.config file.

This following sections provide reference information about the syntax to use in transform files.

Read more: MSDN

Posted via email from .NET Info

0 comments: