2

I'm having a bit of trouble with my web.debug.config and web.release.config files.

To be more specific, my webpage will only use the default web.config file, and completely ignore the debug and release files. This happens not only when I run the project locally, but also when I publish it to an IIS server.

I am using Visual Studio 2010 Ultimate (no Service Pack).

Here are the config files:

web.config:

<?xml version="1.0"?>

<configuration>
    <connectionStrings>
        <add name="MyConn" connectionString="SomeConnectionString"
            providerName="System.Data.SqlClient"/>
    </connectionStrings>
</configuration>

web.debug.config and web.release.config:

<?xml version="1.0"?>

<configuration xmlns:xtd="http://schemas.microsoft.com/XML-Document-Transform">
    <connectionStrings>
        <add name="MyConn" connectionString="SomeOtherConnectionString"
            providerName="System.Data.SqlClient"
            xtd:Transform="Replace"
            xtd:Locator="Match(name)"/>
    </connectionStrings>
</configuration>

As I mentioned before, the website uses the connection string from the web.config file, and not from the web.release.config.

Another interesting point is that in the physical folder to which I published the project, all three config files exist; each exactly the same as they appear in the VS solution.

Suggestions, anyone?

jcjr
  • 1,503
  • 24
  • 40
Yehuda Shapira
  • 8,460
  • 5
  • 44
  • 66

2 Answers2

4

You need to run the transformations. It will not work if you just put the 3 web.config in your folder. You can run this and it will transform your web.config

MSBuild.exe Project.csproj /T:TransformWebConfig /P:Configuration=Release

You will then have a folder in your obj folder created at build that will be called TransformWebConfig. The transformed web.config will be in this.

You can also take a look at this post, he creates a build target to achieve this automatically.

http://vishaljoshi.blogspot.com/2010/05/applying-xdt-magic-to-appconfig.html

Charles Ouellet
  • 6,338
  • 3
  • 41
  • 57
  • I didn't add the config files manually; Visual Studio created them automatically. – Yehuda Shapira Sep 20 '11 at 13:20
  • Yep but you still need to run the transformation. If you follow the steps in the blogpost I sent you it shoud work just fine – Charles Ouellet Sep 20 '11 at 13:28
  • Alas, I can't complete the steps in the blogpost; the post explains how to make an `App.Debug.config` file act just as a `Web.Debug.config` file -- it doesn't resolve the web issue I have. Moreover, many of the steps are irrelevant with a web application. – Yehuda Shapira Sep 20 '11 at 14:21
3

I figured out what I have been doing wrong.

Instead of a Web Application, I was using a Web Site Project.

(The difference between the two is that a Project doesn't actually contain a .proj file. How ironic.)

Now that I've realized the actual problem, it turns out that I'm not the first with it... Here's a link to a previous post with a workaround solution:

How do I do Web.config Transformations with Visual Studio Website Projects?

Community
  • 1
  • 1
Yehuda Shapira
  • 8,460
  • 5
  • 44
  • 66