2 years ago

#62361

test-img

omega

How to use different webconfig configurations based on release type in Visual Studio?

In a .net visual studio project I have

<connectionStrings>
    <add name="sqlname" connectionString=""/>
</connectionStrings>
<appSettings>
    <add key="mykey" value="myvalue" />
</appSettings>

I can then start the project from VS code as debug and release as you all know. But I was wondering if there was a way to set up the web.config like this

<connectionStrings>
    <add mode="debug" name="sqlnametest" connectionString="..._test"/>
    <add mode="release" name="sqlname" connectionString=""/>
</connectionStrings>
<appSettings>
    <add mode="debug" key="mykeytest" value="myvaluetest" />
    <add mode="release" key="mykey" value="myvalue" />
</appSettings>

And it automatically uses the entries here with mode=debug if I start it in debug mode. And uses the entries here with mode=release if I start it in release mode (or publish).

This way I don't need to keep commenting it out the sections based on where I want to deploy.

Thanks

.net

visual-studio

web-config

0 Answers

Your Answer

Accepted video resources