0

I have a C# web project. I opened the configuration manager, for "Active solution configuration" I chose

In the new window I typed the name (Dev), and didn't copy any settings. I checked off "Create new project configurations".

I right-clicked on my Web.config and chose "Add Config Transform". Web.Dev.config appeared indented under web.config as expected.

My web.config contains erroneous database values:

<connectionStrings>
    <add name="PdxContext" connectionString="Data Source=badServer; Initial Catalog=badDB; Integrated Security=true; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>

My Web.Dev.config, in part, contains valid DB values:

<connectionStrings>
    <add name="PdxContext" connectionString="Data Source=.\sql2012; Initial Catalog=test; Integrated Security=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

...but when I select the Dev configuration and hit run, the site is run using the web.config file and not web.dev.config (it tries to connect to a non-existent database named "badDB" on host "badServer").

If I right-click on web.dev.config and choose "Preview Transform" the Transformed Web.config correctly shows that it will use the connectionStrings value from web.dev.config.

Oh, and in the Configuration Manager for Active Solution Configuration for "Dev" the configuration column has "Dev".

Any thoughts?

Developer Webs
  • 983
  • 9
  • 29
  • I also have the exact same issue with the built-in Debug configuration. It ignores values in Web.Debug.config – Developer Webs Aug 23 '16 at 14:44
  • I think maybe it only works under deployment. But then how do multiple developers, working on the same project, but with different configurations work together? I guess they'd have to have their own copy of web.config, and overwrite web.config with their copy every time they did an SVN Update that changed web.config? That seems very clumsy. – Developer Webs Aug 23 '16 at 15:05

1 Answers1

0

The solution can be found here: https://stackoverflow.com/a/3994081

If you're using Visual Studio 2013 also see Matti Price's reply to that post, "For anyone struggling with this in later versions of VS, I had to change <Target Name="CopyWebTemplateConfig" BeforeTargets="Build"> To <Target Name="CopyWebTemplateConfig" BeforeTargets="PrepareForBuild"> And it all worked after that."

Community
  • 1
  • 1
Developer Webs
  • 983
  • 9
  • 29