web.debug.config does not work
Asked Answered
R

1

5

I have a webb aplication where I want to take advantage of the web.debug.config file so that when debugging I use a test database. This does not work for me. I have this in my web.debig.config..

<connectionStrings>
  <add name="connStr" 
    connectionString="Data Source=LocalSqlserverName;Initial Catalog=testdb;Persist Security Info=True;User ID=Myusername;Password=mypassword" 
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

And in my web.config file this connectionstring point to another database server. But when I debug I can see that the connectionstring in web.config file is used instead of the one in web.debug.config. What am I doing wrong here?

Rawls answered 14/9, 2017 at 8:38 Comment(5)
if you deploy your application it would work, but if you debug your application with VS it wouldn't work and always using the web.config fileCervantes
For real? what a worthless option to have a solution from MS... :(Rawls
@Cervantes Are you sure about this? I could have sworn to used this in the past with success. Anyway, most of the time I'm using an xdt:Transform="Replace" instead of the SetAttributes option, but it shouldn't matter.Helsinki
Previously I tried and I had no luck, here is a thread about this : https://forums.asp.net/t/1532038.aspxCervantes
@Rawls If an answer is correct, please mark it accordingly. The same for other questions you have asked.Nickelic
N
12

As @esiprogrammer says it normally only transforms on Publish from Visual Studio.

However you can transform Web.config on build. Add this to your *.csproj file:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets" />
<Target Name="BeforeBuild">
    <TransformXml 
        Source="Web.Base.config" 
        Transform="Web.$(Configuration).config" 
        Destination="Web.config" />
</Target>

Keep the origin configuration in Web.Base.config. It's enough to enable transformation and it works for any XML config file.

Source:

https://mcmap.net/q/420291/-web-config-is-not-transformed-when-debugging-code

Nickelic answered 14/9, 2017 at 8:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.