SkillAgentSearch skills...

Unicorn

A Sitecore utility designed to simplify deployment of Sitecore items across environments automatically

Install / Use

/learn @SitecoreUnicorn/Unicorn
About this skill

Quality Score

0/100

Category

Operations

Supported Platforms

Universal

README

la la la la

Unicorn is a utility for Sitecore that solves the issue of moving templates, renderings, and other database items between Sitecore instances. This becomes problematic when developers have their own local instances - packages are error-prone and tend to be forgotten on the way to production. Unicorn solves this issue by writing serialized copies of Sitecore items to disk along with the code - this way, a copy of the necessary database items for a given codebase accompanies it in source control.

For basic usage, Unicorn has two moving parts:

  • Data provider - The default Sitecore data provider is extended to automatically serialize item changes as they are made to Sitecore. This means that at any given time, what's serialized is the "master copy."
  • Control panel - this tool (/unicorn.aspx) is a page that can sync the state of Sitecore to the state stored on disk (respecting presets and exclusions). You do this after you pull down someone else's serialized changes from source control.

Unicorn avoids the need to manually select changes to merge unlike some other serialization-based solutions because the disk is always kept up to date by the data provider. This means that if you pull changes in from someone else's Sitecore instance you will have to immediately merge and/or conflict resolve the serialized files in your source control system - leaving the disk always the master copy of everything. Then if you execute the sync page, the merged changes are synced into your Sitecore database. Unicorn uses the Rainbow serialization engine, which uses some format enhancements that make it far simpler to merge than the Sitecore default format.

Is this like TDS?

Unicorn solves some of the same issues as Hedgehog's TDS. The major difference in approach is that because Unicorn forces all of the merging to be done on the disk, you never have to manually select what to update when you're running a sync operation or remember to write changed items to disk. Unless you have actual collisions, this saves a lot of time because you can take advantage of Git, SVN, TFS, etc to do automerges for you. That said, TDS and Unicorn have different feature sets and goals. TDS is a monolithic product with commercial support and marketing that does a lot more than just serialization. Unicorn is relatively simple, free and open source, and does one thing well. Use whatever makes you happy :)

Initial Setup

  • Upgrading from Unicorn 3? Great: it's just a NuGet upgrade away. From Unicorn 2.x, you can follow the same directions for 2.x->3.x to go from 2 to 4.
  • You'll need Sitecore 7 or later (including 8.x).
  • Install Unicorn. This is as simple as adding the Unicorn NuGet package to your project.
  • When you install the NuGet package, a README file will come up in Visual Studio with help to get you started.

Using Unicorn

When using Unicorn it's important to follow the expected workflow.

  • When you update/pull from your source control system, execute the Sync operation using /unicorn.aspx if any changes to .yml files were present. Note: Unicorn supports transparent syncing which allows you to skip this step during development.
  • When you commit to source control, include your changed items along with your code changes. Unicorn will automatically serialize item changes you make in Sitecore to items that match the predicate(s) configured.
  • Conflicts in items are resolved at the source control level - at any given time, the disk is considered the master copy of the Sitecore items (due to local changes being automatically serialized as they're made)

Unicorn Features

There are a few special features that Unicorn has that are worth mentioning.

  • You can define multiple configurations, which allow you a lot of flexibility: you can serialize items to different places on disk, set up groups that can be synced separately, and override any aspect of Unicorn in each configuration. Configurations may also define dependencies between each other to enforce a hierarchy.
  • Using Rainbow gives Unicorn a unique, easy to manage serialization format and hierarchy.
  • Unicorn rejects "inconsequential" changes to items. The Sitecore Template Editor likes to make a lot of item saves that change nothing but the last modified date and revision. These are ignored to reduce churn in your source control.
  • During a sync operation, Unicorn can detect improperly merged renamed items (e.g. two serialized items with the same ID in different files) and will report that fact as an error.
  • Automatic retries are performed in the event of a load failure during a sync, which means that syncing items with a missing template along with the template itself in the same sync session will work correctly.
  • Unicorn's logging routines report on exactly what was changed about a deserialized item (changed fields, added/removed versions, moved, renamed, etc)
  • The control panel writes all console output - e.g. of a sync - to both the screen and the Sitecore log file. This provides a handy audit trail of what synchronizations did in the event of someone asking where an item went.
  • You can use FieldFilters to ignore deserialization and changes to specific fields you don't want to sync.
  • The automatic serialization cannot be blocked by event disabling code because it runs at a data provider level.
  • Content editor warnings are shown for items that Unicorn is controlling.
  • You can define custom ways to compare fields, if there are equivalencies that are more complex than string equality
  • There are event pipelines that can be used to hook to sync events. These can be used, for example, to auto-publish synced items.
  • Transparent syncing allows the data provider to read directly from the serialized items on disk, making them appear directly in Sitecore.
  • Super-fast syncing with the 'Dilithium' direct-SQL item reading engine (optional, considered mostly stable but still experimental)
  • Integration with Sitecore PowerShell Extensions to perform Unicorn tasks

You can find further details about Unicorn 4 at Kam's blog:

There is also a series of blog posts detailing Unicorn 3 (and why the Rainbow serialization format exists) at Kam's blog, which are still relevant:

Best Practices

  • If using Helix architecture plan to use one Unicorn configuration per module. You can use Unicorn 4's configuration conventions to avoid repetition and promote a consistent item architecture across modules.
  • If using Sitecore 9 or the Sitecore Configuration Roles module, the Unicorn configuration files are automatically enabled or disabled based on the server role that they are deployed to. If not, make sure to enable and disable configuration files appropriately when developing, and deploying to CE/CM and CD environments. Each config file has a comment header that details when it should be enabled and disabled. Most important is to disable the data provider config when deployed.
  • Always automate your deployments of Unicorn items (see Automated Deployment below). This ensures a consistent item state during deployments.
  • Consider automating local development Unicorn syncing using scripts (e.g. PowerShell or Gulp), which can enable you to have a one-click "post-pull" experience that both builds your projects and syncs any item changes in. Sitecore Habitat does this using a combination of Gulp and the Unicorn PowerShell API.

Automated Deployment

With Unicorn you've got two options for automated deployment of item changes, for example from a Continuous Integration server or production deploy scripts.

Use Transparent Sync

When using Transparent Sync, the items on disk magically appear in Sitecore without syncing. So one automated deployment option is to simply use Transparent Sync and copy your updated serialized items to the deployment target alongside your code. This is advantageous because it's simple to set up and requires no direct intervention with the deployed server after deployment (e.g. a HTTP call).

Use the Automated Tool API

Unicorn has an automated tool API whereby you can invoke actions in the Unicorn control pane

Related Skills

View on GitHub
GitHub Stars267
CategoryOperations
Updated19d ago
Forks114

Languages

C#

Security Score

100/100

Audited on Mar 19, 2026

No findings