Sitecore 10 Content Serialization – Command Line Interface

With Sitecore 10 release, Sitecore has released two new modules for the sole purpose of serializing Sitecore Contents making it easy to port between Sitecore instances. (One dev to another dev or from local to dev/uat or higher environment)

Well.. SCS(Sitecore Content Serialization) is not a new concept all together. We already have tools like Unicorn/TDS in the market that solves the Serialization concerns. But, to have SCS as a module from Sitecore means a lot. They can provide additional support and this SCS module can be extended to provide additional feature with upcoming releases.

SCS comes with two options.

  1. Sitecore Command Line Interface
  2. Sitecore for Visual Studio

Sitecore CLI is free it can be accessed via PowerShell whereas Sitecore for Visual Studio is plugin/extension kind for Visual Studio and needs a separate license.

Note 
Sitecore for Visual Studio requires a separate license that you can purchase at the Team Development for 
Sitecore website.

This post is about Sitecore CLI installing, configuring and using them.

Sitecore CLI Requirements:

  1. Well most of the Sitecore system must already have PowerShell installed.
  2. In addition to PowerShell, Sitecore CLI needs .NET Core. (Sitecore CLI is used as a dotnet tool)
  3. You need to download and install Sitecore Management Services. The usual Sitecore->Control Panel->Administration->Install a package.
    • SMS contains some GraphQL configs/DLLs that is needed for the serialization purposes.

Once the Sitecore Management Service is installed, to install Sitecore CLI

  1. Open PowerShell in admin mode, cd to your Project Solution Root directory.
  2. Use the below command to install Sitecore CLI tool.
dotnet new tool-manifest dotnet tool install Sitecore.CLI --add-source https://sitecore.myget.org/F/sc-packages/api/v3/index.json

Initialize the setup using the below code

dotnet sitecore init

After initializing, let’s connect with our Sitecore instance using sitecore login command. It redirects us to sitecore login page and once given the credentials, we need to check the permission and allow them.

Once this is done, notice in your Project root folder, few new folders/ Sitecore.json file auto created. These are config files which has information like what are files to lookout for and what are their file paths, module configurations and user configurations etc. Please add to gitignore the user configuration/any other config file as necessary as it contains access token/refresh token – individual user login related info. By default, when we install/init Sitecore CLI it takes care of these things. You can add/remove as per your needs.

Most probably we would be having our Solution as per Helix Principles and based on Helix principles along with the code, we have our sitecore content items serialized under serialization folder  in Layer/Module Name/serialization.

We instruct Sitecore CLI to look for “ModuleName.module.json” for sitecore items path for serializing.

Reason we pick up .module.json is because in Sitecore.json config which is created under project root path is instructed to be found in .module.json files.

For this demo consider the below Website.module.json

Ignore the serialization folder, it will be automatically created when we pull the items from sitecore content tree for serialization.

We have added a namespace name SolutionName.Layer.ModuleName

Included the items that are included in the module and their sitecore content tree path. Ignore the Feature-template and Project-template it was just intended to denote any name can be specified for the configuration.

Notice here the order in which they are included. Maintaining this order is necessary as content items which is finally rendered needs the corresponding layouts/renderings and templates first. It might throw an error if the ordering is not followed.

Once, the above steps are completed, we can use dotnet sitecore ser pull to serialize the sitecore items from the content tree to the disk

You can see the items serialized to a YML file available under /serialization folder. Sitecore CLI creates a serialization folder in the same level as of website.module.json which has the serialized items in YML format for the corresponding module.json configurations.

These YML files contains information about the sitecore contents and can be maintained in any version control just like code files.

Once the items are serialized they’re all marked and only when there’s change made in those files, they’re identified by CLI for serialization.

Similarly, once the serialization is complete and it is available in source control, it can be ported to another developer’s local and the deserialization – yml file to sitecore item can be performed using dotnet sitecore ser push command.

References:

Sitecore Content Serialization

One thought on “Sitecore 10 Content Serialization – Command Line Interface

Leave a comment

Design a site like this with WordPress.com
Get started