In a previous article I shared how I configure Sitecore projects with Unicorn when developing sites for SXA. In this article I share some improvements that can be made to simplify the number of configuration files you have to manage.
At this point you may have heard that Sitecore 9+ includes a capability for altering configuration files using custom defined application settings. Kamruz Jaman has written a detailed article covering many aspects of the features.
Let's have a look at what can be added to your configurations to control them per environment.
Begin by starting with a structure similar to this:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" | |
xmlns:set="http://www.sitecore.net/xmlconfig/set/" | |
xmlns:role="http://www.sitecore.net/xmlconfig/role/" | |
xmlns:environment="http://www.sitecore.net/xmlconfig/environment/"> | |
<sitecore role:require="Standalone or ContentManagement"> | |
</sitecore> | |
</configuration> |
The part that is new and most interesting is the namespace added called environment. For this to function we need the "Web.config" to define it.
<?xml version="1.0"?> | |
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> | |
<appSettings> | |
<add xdt:Transform="Insert" key="environment:define" value="Dev"/> | |
</appSettings> | |
</configuration> |
This is going to tell Sitecore that we have a namespace we intend to use in our configuration patches and for this transformed Web.config the value is "Dev". I like to use "Dev", "Int", "Tst", "Prd" for the environment names.
Let's take a look at a more complete configuration for use with Unicorn.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:environment="http://www.sitecore.net/xmlconfig/environment/"> | |
<sitecore role:require="Standalone or ContentManagement"> | |
<unicorn> | |
<configurations> | |
<configuration name="Company.Project.DotCom" description="Files and items for the DotCom website." dependencies="Company.Website" extends="Company.Base"> | |
<predicate type="Unicorn.Predicates.SerializationPresetPredicate, Unicorn" singleInstance="true"> | |
<include name="Forms" database="master" path="/sitecore/Forms/Company/DotCom" environment:require="Int or Tst or Prd"> | |
<exclude childrenOfPath="usa/*" /> | |
</include> | |
<include name="Forms" database="master" path="/sitecore/Forms/Company/DotCom" environment:require="Dev" /> | |
<include name="Content" database="master" path="/sitecore/content/Company/DotCom" environment:require="Int or Tst or Prd"> | |
<exclude path="usa/Home" /> | |
</include> | |
<include name="Content" database="master" path="/sitecore/content/Company/DotCom" environment:require="Dev" /> | |
</predicate> | |
<dataProviderConfiguration enableTransparentSync="true" type="Unicorn.Data.DataProvider.DefaultUnicornDataProviderConfiguration, Unicorn" singleInstance="true" environment:require="Dev" /> | |
</configuration> | |
</configurations> | |
</unicorn> | |
</sitecore> | |
</configuration> |
You'll notice that the include statements have duplicates such as "Forms" and "Content". This is possible because the environment values will limit only one to appear at any given time.
I certainly hope you found this to be helpful. Happy 2020!
No comments:
Post a Comment