ahmd0
ahmd0

Reputation: 17293

Can't figure out web.debug.config vs. web.config substituation in VS2010

Can someone point me to what am I doing wrong here?

I'm trying to set up an ASP.NET web app project to compile with two versions of web.config file for Release and Debug builds. So for simplicity sake, here's my web.config:

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="WhyMicrosoftSucksSoMuch" connectionString="" providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

And then I do the following in web.debug.config:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
      <add name="WhyMicrosoftSucksSoMuch"
           connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename='C:\FilePath\Database1.mdf';User Instance=true"
           providerName="System.Data.SqlClient" 
           xdt:Transform="SetAttributes" xdt:Locator="Match(connectionString)" />
  </connectionStrings>
</configuration>

If I publish it under Debug configuration the resulting web.config looks good, but when I try to run my project from VS2010 also under Debug configuration I get an error when my logic attempts to access database:

The ConnectionString property has not been initialized.

So what's the trick here?

PS. And please don't point me to this document. I tried reading it several times but I get a headache from so much superfluous information. I guess MS doesn't know what brief is.

Upvotes: 2

Views: 617

Answers (1)

Brandon
Brandon

Reputation: 993

When running it under debug mode it doesn't apply any transformations.

It only applies them during publishing. You can put your debug connection string in the main web.config, and add your production connection string to the web.release.config

also, you probably will want to use

xdt:Transform="Replace"

Upvotes: 4

Related Questions