I want to stack app.config files in a similar way to how web.config files work.
I really want to get to the following hierarchy
machine.config (nice and clean no extra config)
Environment config (in source control shared by everyone)
app.config/web.config (config at a non-environmental application level)
Developers hack config (overrides all the things)
I've had a bit of a look at section inheritance with file
or configSource
attributes (see: ASP.NET web.config: configSource vs. file attributes)
However I cant seem to find any way of stacking these more than one level deep, for example
static void Main(string[] args)
{
Console.WriteLine("Setting1: {0}", ConfigurationManager.AppSettings["setting1"]);
Console.WriteLine("Setting2: {0}", ConfigurationManager.AppSettings["setting2"]);
Console.WriteLine("Setting3: {0}", ConfigurationManager.AppSettings["setting3"]);
}
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings file="tier1.config">
<add key="setting1" value="yay"/>
</appSettings>
</configuration>
tier1.config
<?xml version="1.0" encoding="utf-8" ?>
<!--appSettings file="tier2.config"--><!-- using this gives the following: Unrecognized attribute 'file'. Note that attribute names are case-sensitive. -->
<appSettings>
<add key="setting2" value="yay"/>
</appSettings>
tier2.config
<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
<add key="setting3" value="yay"/>
</appSettings>
Is there a way using the file attribute or something else to get multiple levels (more than 2) of config inheritance?