Conditional .NET application settings
.net, app-config
Solution
For your normal appSettings the norm would be to use this:
<appSettings file="appSettings.config" />
For other sections you can use
<mySection configSource="mySection.config" />
You have to have a file per section, and the configSource will only work with relative paths.
For your particular case, I would recommend a folder for each setup/configuration.
<mySection1 configSource="setup1\mySection1.config" />
<mySection2 configSource="setup1\mySection2.config" />
Then you can manually do a text 'find and replace' on the folder name to switch between setups, or run a batch file or build step that switches the folder on the file system (i.e. copy the setup1 folder to a currentSetup folder)
Note that you can't use a configSource on system.serviceModel, but you can for its subsections
Problem
I have a client-server application, where there two options for the server - standalone executable or in another AppDomain in the client, which is very convenient for the debugging purposes. The choice of the server is transparent to the client, the only file that needs to be changed is the client app.config. In order to switch from the standalone server to the local one, some sections need to be un-commented (like nhibernate configuration, which is only relevant to the server) along with individual settings (like authentication implementation, which is again only relevant to the server). As of now, switching between the two modes is tedious and error prone, because one has to (un)comment several sections and individual settings. Is there a way to specify conditional settings/sections in app.config? Or maybe there is a way to include another config file in the app.config? This way we could put all the local server specific settings in another file and only (un)comment its inclusion. I would like to stress the fact, that I wish to have conditional sections, in addition to application settings. Final note. The described scenario is obviously not for production. It is used exclusively for running unit tests. We use mstest for our unit tests. Thanks.