Is there a way to have several hierarchies within the config file using configSource?

186 Views Asked by At

I wonder if there is a way or a workaround to have the config files in the following structure:

App.Config

<configuration>
  <appSettings configSource="AppSett.config">
    <add key="test1" value="test2"/>
  </appSettings>
</configuration>

and my AppSett.config will look like:

<appSettings>
  <add key="test3" value="test3"></add>
</appSettings>
3

There are 3 best solutions below

0
On BEST ANSWER

No, you cannot use external file with partial info to link instead of the default config structure. Config files are special files that conform to config schema and this you cannot use them in the scenario you described.

0
On

Yes, that's what configSource is for, but the configuration section can have content or configSource attribute, not both.

0
On

You can implement this approach by using file attribute instead of configSource:

In your example, you should have file App.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings configSource="AppSett.config">
    <add key="test1" value="test2"/>
  </appSettings>
</configuration>

and AppSett.config

<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
  <add key="test3" value="test3"></add>
</appSettings>