Sitecore ships with a very useful web.config patching feature that allows everything within the
element in the configuration file to be modified and extended. It is a best practice recommendation not to modify the web.config file directly but instead use customised configuration files located within the
App_Config\Include folder to overlay the modifications that your solution requires.
Rather that regurgitate information on how to use the web.config patching mechanism I’ll suggest instead that you start with John West’s post All About web.config Include Files with the Sitecore ASP.NET CMS for a definitive way into this subject.
Developers working with ASP.NET web applications outside of the Sitecore ecosystem are likely to be performing their web.config transformations using Microsoft’s XDT transform syntax. The popularity of the XDT engine is such that it has recently be issued as a NuGet package so that it can be shipped with third-party products. Whilst on the subject of XDT transforms it would be worth pointing out the Slow Cheetah Visual Studio extension for those new to the area. This package enables you to transform your web.config or any other XML file based on the build configuration and preview the outcome – simply invaluable.
Unfortunately the two transformation mechanisms do not always play well together especially if you are developing in the web root. At a recent Sitecore User Group meeting one of the presenters spoke about problems he had encountered when trying to use XDT transforms on configuration files located within the
Fortunately there is a simple workaround to this problem. The
LoadAutoIncludeFiles method of the
Sitecore.Configuration.Factory class gets called to bring in the configuration patch files. This method includes the following logic:
As you can see the config patcher skips over any
.config files that have the hidden attribute set. You can use this behaviour to prevent configuration files that contain XDT transforms from being processed by the Sitecore patching mechanism.