Sunday, 29 November 2015

Keeping your Sitecore configuration files clean

Keeping your Sitecore configuration files clean is very important thing for further upgrades and maintenance. I had a lot experience with projects where configuration files was edited and maintained poorly. This article will provide you with some points you should observe to keep your Sitecore configuration clean and transparent. 

1)      You should definitely avoid editing Web.config file. Rather than that you should use Sitecore patch files mechanism to change Sitecore configuration. In this mechanism, Sitecore processes all .config files in App_Config\Include directory and applies patches to Web.config file.
E.g when you want to replace pipeline processor with your custom one, you could simply edit Web.config. You could delete or comment line with processor you want to replace and write new one. This is the fastest way but the worst. The best way is to create custom patch file:

  Events configuration
<configuration xmlns:patch="">
      <event name="item:creating">
        <handler type="SitecoreExperiments.Common.Events.PreventDuplicates, SitecoreExperiments.Common" method="OnItemCreating" />
      <event name="item:saved">
        <handler type="SitecoreExperiments.Common.Handlers.CustomSaveHandler, SitecoreExperiments.Common" method="OnItemSaved" />

For more informations about configuration patch files see John West post:

You can check how patches applied to Web.config file using special url /sitecore/admin/showconfig.aspx.

Unfortunately Sitecore patches concern only /sitecore branch in Web.config file.

2)      Group Sitecore patches into files that matches specified type of Sitecore region e.g pipelines, scheduling tasks, events. Also make sure that your patches are loaded last – put them in your folder in App_Config\Include and name it with prefix ‘Z_’.

3)      Make developer-specified patches ignored in code repository. Let developers use commited example file (with name e.g FileName.config.example) to create their custom one.

4)      Don’t make Web.config file ignored in code repository. Web.config should be commitable.

5)     Make sure that all Sitecore application configs are in solution. Leaving some of them just in webroot after some installations, leads to misconfiguration and nasty bugs.