2

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?

Community
  • 1
  • 1
undefined
  • 33,537
  • 22
  • 129
  • 198

1 Answers1

2

You can use Slowcheetah for that.

http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5

jennas
  • 2,444
  • 2
  • 25
  • 31
  • We used slowcheetah for a while it was a heap of mucking around we build too many apps for it to be an appropriate solution. Every project in every app needs to have build configs for every environment which was a nightmare to manage also meant we had heaps of config files. We went to machine config for environmental configuration but that's not great either. – undefined Jul 18 '14 at 05:54