Using defines and ifs
You can use XML processing instructions to define and undefine flags and to include sections of the configuration based on the flags. For example:
<configuration> <?define DEBUG?> <components> <?if DEBUG?> <component id="my.component" service="Namespace.IService, AssemblyName" type="DebugVersion, AssemblyName" /> <?elsif STAGE?> <component id="my.component" service="Namespace.IService, AssemblyName" type="DebugVersion, AssemblyName" /> <?elsif PRODUCTION?> <component id="my.component" service="Namespace.IService, AssemblyName" type="DebugVersion, AssemblyName" /> <?else?> <component id="my.component" service="Namespace.IService, AssemblyName" type="DebugVersion, AssemblyName" /> <?end?> </components> <?undef DEBUG?> </configuration>
There is no restriction on where the Xml PI can appear, but keep in mind that ifs cannot be nested.