Here's a comprehensive discussion about updating web.config settings:
Using different Web.config in development and production environment
Although your question may differ, it's worth checking out for valuable insights on switching between live and debug settings provided by various answers.
In my own experience, I favor a method outlined here that offers flexibility across all configuration changes via file-based automation:
The approach involves using pre-build events to replace the web config with another one saved on disk, appending the solution configuration name to the filename. For instance, I have files like web.config.release, web.config.debug, and even web.config.neilathome.
I apply the same technique for conditional code segments by creating partial classes for components that vary between solution configurations. For example, I use sync_timersettings.cs as a partial class containing constants determining update frequencies for a web-service call. Alternatively, all settings can be stored in an app.settings file.
This method has proven very adaptable, allowing seamless swapping of javascript and css elements. By segregating variant configuration aspects into separate files, transitioning from debugging to deploying is simplified.
One important point to note:
#if DEBUG
pnlDebugIncludes.visible = true
#else
pnlReleaseIncludes.visible = true
#endif
Responses to comments:
This tactic works best for scenarios where there are just two configurations - a debug setup and a live deployment. It might not be as effective if you, like me, deal with multiple configurations such as staging or custom setups. To address this, individualize build configurations by setting conditional symbols through the properties page of your web application. This allows proper functioning of #if conditional compile directives based on varying build configurations.
For those seeking guidance on altering markup per configuration, consider integrating partial classes within the application instead of duplicating entire pages. Simply declare corresponding class files with specific titles for each configuration, using them programmatically to alter content dynamically.
When changing non-code files like images or web.configs, employing the file-swap strategy is recommended over altering code directly. Just ensure alternate files aren't deployed during publishing processes.