web.config transforms not being applied on either publish or build installation package

Posted by BenA on Stack Overflow See other posts from Stack Overflow or by BenA
Published on 2010-06-16T14:49:48Z Indexed on 2010/06/16 14:52 UTC
Read the original article Hit count: 355

Today I started playing with the web.config transforms in VS 2010. To begin with, I attempted the same hello world example that features in a lot of the blog posts on this topic - updating a connection string.

I created the minimal example shown below (and similar to the one found in this blog). The problem is that whenever I do a right-click -> "Publish", or a right-click -> "Build Deployment Package" on the .csproj file, I'm not getting the correct output. Rather than a transformed web.config, I'm getting no web.config, and instead the two transform files are included.

What am I doing wrong? Any help gratefully received!

Web.config:

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <connectionStrings>
    <add name="ConnectionString" 
    connectionString="server=(local); initial catalog=myDB; 
    user=xxxx;password=xxxx" providerName="System.Data.SqlClient"/>
  </connectionStrings>
</configuration>

Web.debug.config:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="ConnectionString"
      connectionString="server=DebugServer; initial catalog=myDB; 
      user=xxxx;password=xxxx"
      providerName="System.Data.SqlClient"
      xdt:Transform="SetAttributes"
      xdt:Locator="Match(name)"/>
  </connectionStrings>
</configuration>

Web.release.config:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="ConnectionString"
      connectionString="server=ReleaseServer; initial catalog=myDB; 
      user=xxxx;password=xxxx"
      providerName="System.Data.SqlClient"
      xdt:Transform="SetAttributes"
      xdt:Locator="Match(name)"/>
  </connectionStrings>
</configuration>

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET