views:

144

answers:

1

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"&gt;
  <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"&gt;
  <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"&gt;
  <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>
+1  A: 

Inevitably with these things, the answer was actually staring me in the face. The presence of xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" in the <configuration> node of web.config meant that my transforms weren't matching. Removing it solved the problem.

BenA