Search code examples
c#asp.netweb-configweb-config-transform

Can't get Web.config transformation to work


First of all, we're not using the Web Application project, we're using the Web Site type of project.

In our project we have 3 build configurations, which are: Dev (for development), Demo (for testing) and Live (final release of course).

We have two files (but in the end it'll be 4) which are:

  • Web.config
  • Web.Dev.config

A snippet from the first:

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="SomeConnectionString" connectionString="oldConnStr" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <compilation targetFramework="4.0" debug="false">
      <assemblies>
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
      </assemblies>
    </compilation>
  </system.web>
</configuration>

And this is the transformation:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="SomeConnectionString" connectionString="newConnString" providerName="System.Data.SqlClient" xdt:Transform="Replace" xdt:Locator="Match(name)" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" xdt:Transform="SetAttributes(debug)" />
  </system.web>
</configuration>

It doesn'work at all, neither does the Web.config become 'expandable', screenshot:

Web.config isn't expandable
The icons are from Team Foundation Server

Does anyone know how to make this work?


Solution

  • I found out this can't be done in a Web Site project. It requires a .csproj file, and Web Site's don't have that.