Sitecore – Item Serialization – Using Unicorn

If you have worked on Sitecore for a few weeks, then you would have come across the situation where you need to move your Sitecore content from one instance to another. Be it from your instance to your peer’s or from local instance to DEV or to UAT or may be even PROD.

Now depending upon the item count, one would have either created a package – shared it – installed those packages.

Now imagine, you have an entire content tree paired with Layouts, Renderings and templates added if you have changes in Core DB, imagine the volume of Data that needs to be moved from one instance to another. The Size of the packages would go to GBs.

Also, once you have installed and published a package, you cannot revert the item state to it’s previous state unless you have a separate physical back up of those items.

In order to overcome these difficulties, moving content from one instance to another with ease, we use serialization tools. There are many tools out there. Two of the most popular Sitecore Serialization tools include Unicorn and TDS.

TDS is not an open source. EOD. I didn’t get much chance to play around it while I write this post.  So, I couldn’t comment much on setting it up, it’s ease of use and advantages over Unicorn or other tools.

Unicorn is open source, it’s developed by Sitecore Community members. It’s kind of a free alternative to TDS.

Open Source – We can get to play with it without any fees or licenses. Hence, this post.

You can find lot of articles on web over which one should you pick. Unfortunately, this article is not one of them.

In this post, we will see how we can setup Unicorn, set the content configuration, predicates and serialization folder. How we can transfer content from one instance to another.

Most of the Sitecore Solution would follow Helix Principles, under the same principle, for setting up of a serialization module, we create a separate folder under foundation named serialization and add a serialization project.

Solution 'Markl' (12 of 12 projects) 
Configurations 
Configurations 
Properties 
References 
Env_config 
Features 
Foundation 
Serialization 
Unicom 
Connected Services 
Properties 
References 
App_Config 
App_Start 
a packages.config 
ExceptionHandling 
SitecoreExtension 
WorkFIow 
Solution Items 
Websites 
Guardian 
Markl

We can install Unicorn via NPM. Under, Manage NuGet Packages for the Unicorn Project search for Unicorn and install the latest stable version.

-Article.cshtml 
_MainLayoutcshtml 
Browse Installed Updates 
Unicorn by Kam Figy, Mark Cassidy, 774K downloads 
_Mobiles.cshtml 
Include prerelease 
_logistic.cshtml 
MainNav.cshtml 
_Mobile1.cshtml 
v4.1.1 
Unicorn 
Installed: 
Version: 
4.1.1 
4.1.1 
NuGet Package Manager: Unicorn 
Package source: nugetorg• @ 
nuget.org 
Uninstall 
Judate 
Unicorn is a utility for Sitecore that solves the issue of moving templates, renderings, and other database items between Sitecore instances. This 
package contains both the Unicorn core library and the configuration for it, which is appropriate for web projects. Install Unicorn.Core if you only wanm 
Unicorn.Core by Karn Figy, Mark Cassidy, 783K downloads 
Unicorn is a utility for Sitecore that solves the issue of moving templates, renderings, and other database items between Sitecore instances. 
Unicorn.Roles by Kam Figy, Mark Cassidy, 492K downloads 
Adds security role syncing to unicorn This package contains both the core library and the configuration for it, which is appropriate for web projects. 
Install unicornRoles.Core if you only want the library. 
Unicorn.Users by Kam Figy, Mark Cassidy, 368K downloads 
Adds user syncing to Unicorn. This package contains both the core library and the configuration for it, which is appropriate for web projects. Install 
Unicorn.UsersCore if you only want the library. 
Unicorn.Roles.Core by Kam Figy. Mark Cassidy, 519K downloads 
Adds security role syncing to unicorn Install the non-core package to get config files. 
Unicorn.Users.Core by Kam Figy, Mark Cassidy, 388K downloads 
Adds user syncing to Unicorn. Install the non-core package to get config files. 
MagicalUnicorn.MvcErrorToolkit by pure Krome, 24.6K downloads 
Magic fairy dust sprinkled Over the ASP.NET MVC framework to give you greater control Of error handling. 
Each package is licensed to you by its owner. NuGet is not responsible for, nor does it grant any licenses to, third-party packages. 
v4.1.1 
v41.1 
v41.1 
v41.1 
v41.1 
Options 
Unicorn is a utility for Sitecore that solves the issue of mcwing templates, renderings, 
and other database items between Sitecore instances. This package contains both the 
Unicorn core library and the configuration for it, which is appropriate for web projects. 
Install Unicorn.Core if you only want the library. 
Author(s): 
Date published: 
Project URL: 
Report Abuse: 
Unicorn.Core (s 
4.1.1 
Kam Figy, Mark Cassidy 
View License 
Monday, July 22, 2019 (7/22/2019) 
https://github.com/SitecoreLlnicorn/lJniccrn 
https://wvvwnuget.org/packages/unicorn/4.1 1 /ReportAbuse 
sitecore, serialization 
4.1.1) 
Rainbow 21.1)

Once, it’s installed, you will see the required DLLs, App Config Folders added.

Serialization 
Connected Services 
Properties 
References 
App_Config 
Include 
Unicorn 
Unicorn.AutoPublish.config 
unicornconfig 
Unicorn Config s. Default example 
Unicorn Configs.oependency.config.example 
unicorn Configs.NewItemsOnIy.exampIe 
UnicornCustomSerializationFolder.config.example 
unicorn.DataProvider.config 
UnicornDilithium.config.example 
unicorn.R)werShell.config 
UnicornRemOteconfig.disabIed 
UnicornUl.config 
unicorn UI. DeployedContentEditorWarnings.configdisabled 
Unicorn UI. IdentityServer.config 
Unicom.zSharedSecretconfig.example

The First thing you do is Enable the IdentityServer config. Most of us must have moved to Sitecore 9.1 or above. The Identity Server config is has the necessary configs for managing the authentication formalities of Unicorn with Identity Server components.

One thing which I would like to point here is, the Site Neutral Path value is Case sensitive. /unicorn.aspx and /Unicorn.aspx is different.

So, enable this config and add the required Site Neutrals.

To Check whether Unicorn has been successfully installed, go to <<Your Sitecore Instance>>/Unicorn.aspx. You will see Unicorn Home Page. If you are being asked to sign in to Sitecore Console, sign in as Admin and Check again. If you are being circled between Sitecore login page and Unicorn Start Page asking for login,  seems like Identity Server Config is not setup properly. Recheck whether you are using the same URL pattern or whether you have published your Unicorn Config changes done so far.

Now, let’s talk about other key configurations.

  • Configurations: Each configurations includes predicates, sync configurations – items/Parent Items aka Folders that needs to be included for Serialization, updating the link database, search index etc.
  • Predicates: Predicates include configurations for mentioning the sitecore items needed to be included for Serialization. You have options for including the parent item alone, excluding the child items and few other customizations.
  • For getting started  these configs would suffice. MySitecore and Mark 1 are the parent folders under respective categories that are present in my Sitecore Instance.
sitecore 
Content 
Home 
Email 
Mark 1 
Bosch 
Guardian 
MySite
Controllers 
a Devices 
Layouts 
Feature 
Foundation 
MySitecore 
Guardian 
O Markl
  • We have added configurations for including the Sitecore Items. Let’s work on setting up Data Store.

Before going up further I would like tell you about Serialization Process.

“Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.”

This is the most amazing and absolute definition for the Serialization.

Unicorn converts the Sitecore Items in Sitecore Database to Serialized State aka .YML Files.

Coming back to our Data Store discussion, Data Store is nothing but a place for storing these Serialized Data (.YML Files). So that we can make use of this data store for Serialization/Deserialization of the items.

Another key feature of Unicorn is, it let’s the Source Control handle the version management. I will explain this towards the end of this post.

  • The Data Store is unique for each configurations. The Data Store is mentioned in a separate config,  Unicorn.CustomSerializationFolder.config
  • Just like each patch config we include for other Helix Modules, it is wise to include our custom Unicorn Configs under separate Configuration Folder. This will be helpful during Version Upgrades.

To Sum UP,

Foundation 
Serialization 
Unicorn 
Connected Services 
Properties 
References 
App_Config 
Include 
Unicorn 
zUnicorn 
Unicorn.Configs.DefauItconfig 
Rainbowconfig

Now, after publishing the Unicorn Config changes done so far, open <<Your Instance>>/Unicorn.aspx and Do initial Serialization.

Initial Serialization is some thing that you do only when you setup the Unicorn for the first time to a instance. It Serializes the current Sitecore items and stores them the target Data Store.

Repository Markl 
Name 
Content 
Renderi ngs 
Templates 
Serialization 
Date modified 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
Type 
File folder 
File folder 
File folder 
File folder

Some Samples

Repository Markl 
Name 
Serialization 
Content 
Markl Guardian 
Date modified 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/28/2019 12:20 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
12/26/2019 11:25 PM 
Type 
File folder 
File folder 
File folder 
File folder 
File folder 
File folder 
File folder 
YML File 
WL File 
YMC File 
YML File 
WL File 
YML File 
WL File 
YML File 
File 
WL File 
YML File 
WL File 
Size 
Around the World 
Business 
India Today 
Logistics 
Shared Content 
Sports 
Technology 
sooyml 
Around the World.yml 
Article Page.yml 
Article Page_650b51b5-23a7-4a42-90ae-m 
Businessyml 
Home.yml 
India Today.ynnl 
Log istics.yrnl 
Shared Content.yml 
Sports.yml 
Technology.yml 
12 KB

A YML Files opened in Notepad++ having information about the item and it’s fields

newl RWeb.confg 
ID: "b5dcB76c-99co-49a3-991a-3e12c3828427" 
Parent : 
" 4b52b6b1-70b5-48be-a01b-2cad69b21ccd" 
rernplate: "af2173d2-2aea-4ade-901c-7d7eff2f7004" 
Path: / sitecore/content/Mark 1/Guardian 
DB: master 
Shar e dB : 
- ID: "06d5295c-ed2f-4a54-9bf2-26228d113318" 
Hint: 
Icon 
value: Network/ 32x32/environment. png 
- ID: "1172f251-dad4-4efb-a329-oc63500e4f1e" 
Hint : Masters 
Type: TreelistEx 
value: 
{A87AOOB1-E6DB-4SAE-3BS4-636FEc3BSS23} 
- ID: "dec8d2d5-e3cf-48b6-a653-8e69e2716641" 
security 
Hint: 
ar sitecore\content Editor Ipe 1+1 ten: rename 1+1 tern: create 1+1 tem:write l+item:readl Ipdl+item 
Langua ges : 
— Language : en 
Versions : 
— Version: 
Fields : 
- ID: "05a567fa-28b7-41ba-a890-289d553a69cf" 
Hint: website Name 
value: Guardian 
- ID: "Oa443f35-d309-4a3c-bb5e-6155b83e52b6" 
Hint: PageNotFoundur1 
value: /sitecore/content/Mark 1/Guardian/404 
- ID: "Oc36da5e-03c3-4929-a03d-4c61ed0a2aaf" 
Hint: website Description 
value: Local website intended to be my Playground. 
- ID: "25bed78c-4957-4165-998a-ca1b52f67497" 
Hint: 
Created 
value: 20190714T163507E 
- ID: "2803cd55-13B4-49bb-a1ec-98d4351eeef4" 
Hint: Host Name 
Value: _ 
- ID: "6bOfcd7d-9112-40e3-ad7e-Oe8691dabf20" 
Kine: ExceptionPageür1 
Value: / sitecore/content/Mark 1/Guardian/500

Once, everything is setup as mentioned above, you will end seeing a screen similar to the one below.

version 4.1.1 | QPtiQns 
Configurations 
Some configurations prevent the 'sync all' checkbox because they include predicates that rely on (currently) invalid root paths. You likely need to sync one or more 
base configurations. 
Markl.Default 
Default Unicorn Config for Mark 1 
Show Config

Click the Show Config to check your Configurations.

Reserialize – Serializes Sitecore Items from Sitecore Content Tree to Data Store as .YML Files.

Sync – De Serializes the YML Files to Sitecore Database. Meaning whatever the state in your YML File will be moved to your Sitecore Database.  Based on the Situation and requirement perform Reserialize or Sync.

That’s almost it. You can move the Serialization Folder to your source control and let it handle the version management.  I would have given a heads up about this in the earlier part of this post.

Meaning,

g ithub.com/Pushpaganan/Mark1/tree/master/Serialization/Content/Mark%201/Guardian 
r jump to.„ 
pull requests Issues Marketplace Explore 
e Pushpaganan / Markl private 
C) Security 
@Watch O 
Insights •O Settings 
star 
O Code 
C) Issues O 
Pull requests O O Actions Projects O 
n 
Create new file 
Fork 
Find file History 
Branch: master • Markl / Serialization / Content / Mark 1 / Guardian 
Pushpaganan Added unicorn Serialization Folder and YML Files 
Upload files 
Around the World 
Business 
India Today 
Logistics 
Shared Content 
Sports 
Technology 
404.yml 
500.yml 
Around the World.yml 
Article Page.yml 
Added Unicorn Serialization Folder and YML Files 
Added Unicorn Serialization Folder and YML Files 
Added Unicorn Serialization Folder and YML Files 
Added Unicorn Serialization Folder and YML Files 
Added Unicorn Serialization Folder and YML Files 
Added Unicorn Serialization Folder and YML Files 
Added Unicorn Serialization Folder and YML Files 
Added Unicorn Serialization Folder and YMC Files 
Added Unicorn Serialization Folder and YMC Files 
Added Unicorn Serialization Folder and YML Files 
Added Unicorn Serialization Folder and YML Files 
Latest commit feS4a63 3 days ago 
3 days ago 
3 days ago 
3 days ago 
3 days ago 
3 days ago 
3 days ago 
3 days ago 
3 days ago 
3 days ago 
3 days ago 
3 days ago

So that, whenever you make the changes to Sitecore Item, it will be available in your changes tab.

Just like maintaining our Visual Studio files, we can mange Sitecore Content as well. In this way the Sitecore items can be moved across peers. Get the latest version of the Data Store and Perform a Sync Operation

Unicorn also provides a powershell script that can be added to your devops pipeline and the sync of Sitecore YML Files to Sitecore DEV/UAT or PROD database can be controlled along with Auto Publish option.

2 thoughts on “Sitecore – Item Serialization – Using Unicorn

Leave a comment

Design a site like this with WordPress.com
Get started