Reputation: 150108
I have a web application in VS2010 with a web.config like this:
...
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=MyProdDb;Initial Catalog=MyCat;User Id=MyUser;Password=MyPass;"
providerName="System.Data.SqlClient" />
</connectionStrings>
...
and a Web.Debug.config like this:
...
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=MyDevDb;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
...
The project is set to create a Debug build, and when I run it in the debugger, I get MyProdDb
rather than MyDevDb
What am I missing?
Upvotes: 5
Views: 1606
Reputation: 150108
UPDATED INFORMATION
Arbitrary XML-based .config files can now be processed, and the processing can happen at build time rather than at deployment time
Brilliantly, the transforms can also be previewed directly in Visual Studio.
Upvotes: 4
Reputation: 34238
As people have said the web.config versions only get applied at publish (MSDeploy) time. The normal way you would do things is to have your 'Debug' config in the actual web.config file and make changes to that for each of the deployment scenarios you have.
Upvotes: 3
Reputation: 30666
Web.config transformations gets processed at publish time only. When debugging (even in release mode), the basic Web.config file is being used.
Upvotes: 0
Reputation: 1038730
What am I missing?
You are missing the fact that web.config transformation occurs only when you do a deployment. If you don't publish your web application you cannot expect any transformation to occur. If you just run your website locally by hitting F5 no transformation will occur. It's only when you publish the application that the transformation is performed.
Upvotes: 3