Sitecore 5.3 introduces some notable configuration enhancements: ability to include separate configuration files and variable declaration.
Variables
“sc.variable” directive is used to declare a variable which can be referenced in other branches of configuration hierarchy.
In 5.1 / 5.2 it’s only possible to refer to parent attributes:
<parent parent_attribute=”parent_value”>
<child childattribute=”$(parent_value)” />
</parent>
// can’t use $(parent_attribute) here
5.3 supports and uses this:
<sc.variable name="dataFolder" value="/data" />
…
<settings>
<setting name="LicenseFile" value="$(dataFolder)/license.xml" />
</settings>
So finally, when moving data folder to a different location only one variable declaration has to be updated. Interestingly enough, Sitecore log4net appender knows about $dataFolder variable as well:
<appender name="LogFileAppender" type="log4net.Appender.SitecoreLogFileAppender, Sitecore.Logging">
<file value="$(dataFolder)/logs/log.{date}.txt" />
Includes
Using the “sc:include” directive, you can include another configuration file on the spot.
Example:
<connections serverMode="File">
<sc.include file="/App_Config/$(database)/$(serverMode)Connections.config" />
<sc.include file="/App_config/$(database)/Timeouts.config"/>
</connections>
The included file must be a valid xml document with document element root node:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nodes that should be included go here />
</configuration>
The example demonstrates a powerful idea of combining includes with variables/attributes: by having dynamic values as a part of include file path, you can swap larger sections of configuration file based on one master setting.
Tricks
Both includes and variables support nesting:
- Configuration file that is being included can contain include directives as well
- Configuration file that is being included can declare variables used in the parent file
Variables can be defined more than once – the last declaration wins, as long as they are defined in one configuration file. It’s not possible to re-declare variable already declared in included configuration file.
Watchers
Yet another good thing is new configuration watchers. Since we don’t store all settings in web.config now, changes to files in \App_config folder will not result in automatic application restart.
Instead, changes to main configuration files will be effective immediately: change /App_Config/commands.config and use new commands without restart.