How to: Sitecore 10 Content Serialization Setup

Jatin Prajapati
6 min readAug 30, 2020

With Sitecore 10 release, we have lot new feature, like Containers, ASP.NET Core, and Serialization, are available for developers.

Today I’m going to give you a step by step walkthrough for how to setup content serialisation for Sitecore 10.

What we need

I assume that you have already a fully functional Sitecore 10 setup on your local development environment.

Any edition of Visual Studio 2017/2019.

Important: All the commands are executed in PowerShell.

Introduction

With release of Sitecore 10, the Sitecore Content Serialiazation (SCS) is a system for serializing, sharing and deploying content items, as well as keeping them in the version control.

So far before release of Sitecore 10, we are using the Unicorn or TDS for serialization the Sitecore content items to deploy or store in version control. But now with Sitecore 10, we are no longer dependent on these tools and we have a very known JSON based configuration to setup content serialization.

With the JSON base configuration, you can configure which items to include and which ones to exclude, and which operations to perform on the content items.

Now let’s see how we can setup the Sitecore Content Serialization (SCS).

My workstation setup for your reference.

I’ve created a blank Visual Studio solution named “SC10Learning”, and following image shows the basic setup of the solution. Going forward, while creating any VS project, I will create under this solution and hence I’ll not explicitly mention it further.

And the folder structure is as following:

You need to take care of changing the paths / folders according to your workstation setup.

We need the sitecore.json file at the solution root folder. Please create a sitecore.json file with following content.

You are free to change the values for defaultMaxRelativeItemPathLength and defaultModuleRelativeSerializationPath variables.

Install Sitecore Command Line Interface (CLI)
The Sitecore Command Line Interface (CLI) allows console communication with a Sitecore instance.

The Sitecore CLI requires that .NET Core is installed on your workstation. Please download and install the .NET Core 3.1 from Microsoft.

Please note that the command required “dotnet new tool-manifest” is available in .NET Core 3+ version but not in older versions.

Once you are done with installing the .NET Core 3.1, open the PowerShell with administrator privileges and run the following commands to install Sitecore CLI as a local project tool. My solution root folder is “C:\learning\SC10Learning”.

If multiple developers are working on the same project, they just have to execute dotnet tool restore to install Sitecore CLI.

The documentation on doc.sitecore.com says to verify the Sitecore CLI installation by typing sitecore in the powershell. However sometimes you get a message that sitecore is not recognized as the name of a cmdlet, function, script file or operable program. In that case, you can try dotnet sitecore command and it will work.

Install Sitecore Management Service

The Sitecore Management Service is a package that you must download and install in your Sitecore Content Management (CM) instance to support Sitecore Command Line Interface.

To install Sitecore Management Services in CM:

a. Download the Sitecore.ManagementServices package file from the Sitecore Downloads site.

b. On the Sitecore Launchpad, click Control Panel, Install a package. Then follow the instructions to install the Sitecore.ManagementServices package file.

Log in to a Sitecore instance with Sitecore CLI

You must login to the Sitecore instance to make the Sitecore CLI work flawless. We have following two options for authentication and authorization:

  • An interactive user login, using a device code flow.
  • A non-interactive client login, using a client credentials flow. This is used by clients such as Continuous Integration servers.

In this article we will use an interactive user login, and for that to work we need URL of the identity authority, URL of the Sitecore instance, username and password.

To log in:

  1. In PowerShell, go to your Sitecore project folder.
  2. Login with this command (if sitecore login does not work please try dotnet sitecore login command):
    sitecore login — authority https://sitecore-10-identityserver.dev.local — cm https://sitecore-10-sc.dev.local — allow-write true
  3. The sitecore login command opens a login web page in your browser. Enter your username and password and click OK.
  4. The sitecore login command stores your login arguments in the .sitecore\user.json file together with an access token. You are not logged in, and you can close the login web page.

Important: Do not commit the .sitecore\user.json file to source control as it contains privileged information.

Setup project

Now let’s setup the project to have configurations for Sitecore serialization.

Go to your solution directory and execute the sitecore init command. After successful execution you will see the sitecore.json file created in the folder. See below image for your reference.

Now, I created a new module under Feature (in Sitecore CM) folder named ‘Metadata’ to take as an example for this article, and it looks like below image in my Sitecore. We will setup serialization for the Metadata module.

Now open your sitecore.json file in any text editor and set the modules element value to as shown in the following image.

Now create a new project in Visual Studio. Please make sure you follow Helix practice for setting the projects. My project looks like blow.

Now create a new file named Metadata.module.json under the Metadata folder in file system and make necessary changes for the namesapce, path and other options according to your workstation setup.

Ok. Now we are ready to serialize the items for the Metadata module.

Execute the sitecore ser pull command from the folder where you have sitecore.json file, means a root directory of your project, and you can see the PowerShell terminal will show you the serialized items.

And if you check the Metadata project directory on your file system, you will find that the serialization directory is created and the serialized items are stored as .yml files.

So, this way you can setup other projects as and when you create and have a serialization using Sitecore CLI.

You can use the sitecore ser watch command to monitor changes to content items in a Sitecore instance and automatically serializes the changes to your file system.

Happy Sitecoreing!!!!!

--

--