Channels ▼

Joydip Kanjilal

Dr. Dobb's Bloggers

web.config Transformations in Visual Studio 2010

April 28, 2011

Every ASP.NET application contains one or more web.config files. These files store configuration details of the web application. Before Visual Studio 2010, we had to manually change the web.config file settings (set at the time of development) prior to deployment.

Visual Studio 2010 now comes with a new and interesting feature named "web.config transformation". It enables you to automatically modify or transform the application's web.config file during deployment. Visual Studio 2010 allows you to have multiple application web.config files. If you create a new web application, you'll notice that there are two versions of web.config file by default — web.Debug.config and web.Release.config. If your application is set to debug mode, the web.Debug.config file would be used at the time of deployment. If your application is set to release mode, the web.Release.config file is used as the application's configuration file. Adding web.config transformations is simple — just select the application's web.config file, right-click on it, and then select Add Config Transforms.

Here is how the new transform for release configuration would look:

<?xml version="1.0"?>
<configuration 
xmlns:xdt=http://schemas.microsoft.com/XML-Document-Transform>
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
</configuration>

Now, suppose we have specified a connection string setting in the web.config file, as shown below:

<connectionStrings>
  <add name="Test" 
    connectionString="Some connection string" 
    providerName="System.Data.SqlClient" />
</connectionStrings>

As there is no Transform attribute associated with the latter snippet, this connection string setting would apply to all versions of web.config file at the time of deployment.

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video