There are several instances when you make updates to your Sitecore.config file, changes can include:
- Adding new pipelines and processors for any custom feature implementation.
- Updating/overriding the default values for some of the setting values like cache sizes and etc.
- Adding new Sitedefination for your Sitecore instances.
So, to make any of the updates mentioned above, we have to perform following task(s):
- Code changes (class file updates) and/or
- Configuration file(s) changes (this is to make sure we register the changes in Sitecore)
Once you are done with you class and config changes, we need to register the changes in Sitecore, this is required so that Sitecore can identify the changes you made, and the functionality works as expected.
There are two approaches for registering the custom updates in Sitecore:
- By adding/updating the config changes directly in Sitecore.config file (not recommended) or
- Creating a patch file (with extension .config) which includes all the changes required, and placing file under App_Config/Include folder, we can create separate sub folders as well.
Both the approaches works fine as expected, but there is an issue with approach 1.
How would you handle the updates in Sitecore.config file when you are planning for an upgrade later?, provided that you made several changes to Sitecore.config file, it may results issues after the upgrade.(think about it carefully before making changes directly to default Sitecore.config file)
How about if we think about creating a patch file, and putting all our changes there?, and this works well even if you are going for an upgrade at later stage, as you are not adding/updating anything on default Sitecore.config file directly, all the custom changes are coming as part of your patch file(s), This also helps in easy maintenance and troubleshooting.
Patch files are merged with Sitecore.config in alphabetical order. This means configuration in a patch file named a.config will appear before configuration in a patch file named b.config.
If the same configuration is found in multiple patch files, the configuration from the last patch file processed is the configuration that is used.
We can create as many patch files as we want, it all depends on the feature/requirement(s) and the way you want to organize your configuration files in your solution.
For example – you can create separate patch file for any Import functionality we have in the system, and this includes all the settings that needs to be added for specific one, also, there can exists separate patch file which includes custom indexes if exists any?
Note: Patching only works on the Sitecore configuration section, no other file or section can be patched with this.
Place in solution where patch files are placed, i.e under “App_Config/Include” folder
Sitecore patching can be used for following operation(s):
- Adding a new setting
- Deleting a setting
- Adding or updating an attribute.
- Inserting an element before a specific element.
- Inserting an element after a specific element.
Simple example of Sitecore Patching:
This will set the default database for your website to master, this helps in testing the application without publising changes to web db
(Make sure to revert it back once you are done- and never make this change in QA/Production)
How to see the result after Patching?
Now, how we can see the file which includes all the patches which we have applied, there is no physical .config file which can be used, In order to see the final result, please use this URL
Sitecore patching is an important part of day to day development, and we should leverage this as much as possible, to make sure we can make the system more stable and maintainable.
You can learn more about Sitecore Patching here:
Thanks and let me know if you have any feedback/comments on the same.
Happy learning 🙂