Thursday 23 December 2021

Sitecore 10 Content Serialization using Command Line Interface

Introduction

Sitecore Content Serialization (SCS) is a system for serializing, sharing, and deploying content items, as well as keeping them in version control. This is helpful for developers that work on the same project to synchronize the Sitecore changes between their individual development environments.


Sitecore Content Serialization (SCS) comes with two options.

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


Install Sitecore Management Service

You must install the Sitecore Management Service package to your CM instance and you can download the package from the Sitecore CLI Download page and directly install this package to Sitecore Instance. The usual Sitecore->Control Panel->Administration->Install a package.


Once the Sitecore Management Service is installed, then need to install Sitecore CLI.

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.
  1. Open PowerShell in admin mode and go to your Project Solution Root directory.
  2. Use the below command to install the 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
  • # To install the Sitecore CLI as a global tool (not recommended):
  • dotnet tool install Sitecore.CLI -g --add-source https://sitecore.myget.org/F/sc-packages/api/v3/index.json

Install Sitecore CLI Commands

After successful installation, you can verify it using
"dotnet sitecore"
because as per the Sitecore installation document, you have to hit only
"sitecore"
but it throws an error.

Login to Sitecore Instance with SCLI Interface

There are two ways to login into Sitecore using SCLI-
  1. An interactive user login, using device code flow.
  2. A non-interactive client login, using client credentials flow.
Interactive User Login

Before logging into Sitecore, we have to initialize SCLI as mentioned below:
  • Open the Powershell in administrator mode and go to the Project Folder and run the following command-
"dotnet sitecore init"

  • As you hit this command in the file system, you can see the sitecore.json file and .sitecore folder.



  • Now, login into Sitecore and run this command (change the parameters accordingly)-
"dotnet sitecore login --auth https://sc10identityserver.dev.local --cm https://sc10sc.dev.local --allow-write true"
  • Once you hit this command, a Sitecore login window will start opening in your browser and click Yes, Allow and close the browser.



  • Now create a file under your project folder "1.Media.Module.json" in my case and add the following details:


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.

  • Remember, if you are adding multiple paths then do have the templates on the top else you will get an error while deserialization.

    • After setting all this, use the below serialization command for the push & pull activities where ‘ser’ is the shorthand for the serialization keyword. After running the pull command, you can see the YML files in a file system.

    "dotnet sitecore ser pull"
    "dotnet sitecore ser push"




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 Media.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.
  • You must run this command before you start making any changes to your items in your local instance. This will automatically serialize your items to file system. Run the below command to enable transparent sync
    "dotnet sitecore ser watch"

  • For other commands or the help section, run the command as mentioned below:
    "dotnet sitecore --help"

Found some issues while installing


Solution: Need to install Netget in the project solution.


Sitecore Publishing Service 7.0 Installation Guide

  About the Publishing Service module The Publishing Service module is an optional replacement for the existing Sitecore publishing methods....