Is it possible for me to have an <appSettings />
section in my app.config which contains a number of settings, but which also references an <appSettings />
section in a different file?
This would allow me to keep config options that only the developer should be interested in, e.g. options to show debug output on the main window (very messy but useful to me) or to save certain files to specific locations.
Specifically, this is what I'm trying to achieve:
<!-- this is the appSettings section of the normal app.config file,
which also contains everything else that app.config would -->
<appSettings configSource="AppSettings.config"> <!-- references another file -->
<add key="deployment_config_option1" value="1"/>
<add key="deployment_config_option2" value="2"/>
</appSettings>
<!-- this a new appSettings section of another file called DevSettings.Config
which only contains settings us developers are interested in
by keeping these settings in a different file,
I can ensure it's never deployed -->
<appSettings> <!-- references another file -->
<add key="show_debug_on_screen" value="true"/>
<add key="save_copy_to_desktop" value="false"/>
</appSettings>
YES. The doc is somewhat thin given the number of scenarios possible, but as per the quote below says there is a merge in the case of the appSettings tag only.
Because any changes to the Web.config file cause the application to restart, using a separate file allows users to modify values that are in the appSettings section without causing the application to restart. The contents of the separate file are merged with the appSettings section in the Web.config file. This functionality is limited to the appSettings attribute.
A test of this (below) in the case of ASP.NET shows that it works using <add>
tags. Utilizing fancier stuff like a <clear>
tag in the subordinate file could obviously present issues, though I didn't test that edge case. Can't speak deployment technologies other than ASP; Machine.Config wasn't tested, either.
In a web.config file:
<appSettings file="_config\AppSettings.Config">
<add key="testing-1" value="Web.Config" />
</appSettings>
In a "_config\AppSettings.config" file:
<appSettings>
<add key="testing-2" value="_config/AppSettings.config" />
</appSettings>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With