What is Unicorn?
Unicorn is notably different from TDS. It's automatic beyond initial source setup. Any new items, changes to items or deleted items within managed areas will automatically be picked up by Unicorn and updated on the disk.
One benefit of Unicorn is that developers aren’t required to do an additional step of syncing Sitecore items.
The other major benefit of Unicorn is that its design works much better with the Sitecore Helix architecture than TDS. This is due to the specificity of its sources because developers don’t need to include a lot of the common tree items like they would in TDS. This significantly reduces the number of projects to maintain.
Working with Unicorn
To efficiently work with Unicorn, developers need to understand its jargon:
- Unicorn Source: A configuration element which manages a selection of paths and their children (by default). Anything covered by a Unicorn source will be stored onto the disk in the location defined by that source
- Sync: An action taken which takes the data stored on the disk and writes it to Sitecore. Note that this will overwrite local content if it's not on the filesystem as well. Since Unicorn does this automatically it's rare for this to happen
- Reserialise: The reverse of a sync. Items on the disk for the given Unicorn source are removed and updated with new serialised variants from Sitecore, even if they're different. Generally, a Reserialise is only done when a Unicorn source is first created, but there are other scenarios where developers might want to use it
Assuming all Unicorn sources are already set up and in place, Unicorn couldn’t be simpler to work with.
Whenever local branches are updated with potential new content, go to the Unicorn control panel at [siteUrl]/unicorn.aspx and select Sync all the things to update local Sitecore instance with the new content defined on the disk.
When creating new items in Sitecore, correct setup of sources mean that you won’t have to go out of your way to sync items or any of their changes - they'll just show in the file system.
It’s a good habit to get into Reserialising Unicorn sources when changes have been made to an existing template. This ensures that any items that also implement that template are updated with the correct data from Unicorn.
Creating a new Unicorn source
The first step to working with Unicorn sources beyond the initial installation via Nuget is to create a Unicorn source in a configuration file.
Since Unicorn configuration is in the Web.config you can take advantage of Sitecore patching to include it.
Below is an example of a very basic Unicorn source:
This Unicorn source is set up to capture any items created under the sitecore/content/Home path on the master database. Any time there’s a modification to this item or items beneath it, the Unicorn source will be updated.
At Codehouse we're constantly exploring new technologies and challenges that will improve the development process. We continually work on exciting design and build projects often on CMSs like Sitecore.