Managing complex Web.Config files between deployment environments
We split out all region specific settings into thier own config file. Under the root of the web app we create a config folder and place the region specific settings there. So whatever files are living under the root of config will get picked up.
our web.config looks something like:
...<appSettings configSource="config\appSettings.config"/><nlog configSource="config\nlog.config"/><applicationSettings> <MyApp.UI.Properties.Settings configSource="config\Settings.APGUI.config"/> <MyApp.BusinessServices.Properties.Settings configSource="config\Settings.Business.config"/> <MyApp.Auditing.Properties.Settings configSource="config\Settings.Auditing.config"/></applicationSettings>...
So if we are deploying to the release region the build tool will just have an action to replace the files in the root of config with the files from the appropriate region folder. The file structure looks something like:
ADDED: This is how the source control structure looks, the deployed app would just have the config dir with no sub folders or course
\Root web.config \Config appsettings.config services.config logging.config \release appsettings.config services.config logging.config \debug appsettings.config services.config logging.config
It is pretty clean and supported by any automated build tool(copying/replacing files). The nice side effect is that developers can create different flavors and keep them under source control without affecting the "real" configs.
You want the XmlMassUpdate task in MSBuildCommunityTasks (does what you're trying to do with your xml console app)
http://msbuildtasks.tigris.org/
use it like this
<XmlMassUpdate Condition=" '@(ConfigTemplateFile)'!='' And '@(ConfigSubstitutionsFile)'!=''" ContentFile="@(ConfigTemplateFile)" SubstitutionsFile="@(ConfigSubstitutionsFile)" MergedFile="@(ConfigFile)" ContentRoot="/configuration" SubstitutionsRoot="/configuration/substitutions/$(Configuration)"/>
You could use Build Events to manage your web configs. Hanselman has a good article about it.
Basically you have all your different web.configs in the solution you then create (some) new build types. Depending on the build type you run a web.config is copied over the referenced one!