简体   繁体   中英

VS2010 debug/release.config not working

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?

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM