You use serialization to serialize an entire Sitecore database, or a series of items in a database, to text files. You then use these text files to transfer this database, or series of items, to another database or Sitecore solution.
You typically use Sitecore serialization in combination with a source control system to make it easy for developers to synchronize database changes between the local databases that they use for development. The source control system also keeps track of database changes and allows you to compare different database changes.
There are many tools that provide Sitecore serialization for content management in different environments and different machines.
You have three serialization access points in Sitecore. They all use the same general settings in the App_Config\Sitecore\CMS.Core\Sitecore.Serialization.config file.
Below, we are going to discuss in detail the Sitecore CLI.
Sitecore Command Line Interface (CLI) is a tool that you install in a terminal. You can install Sitecore CLI either as a local tool for individual projects or as a global tool for all projects. It will not provide a user interface.
As the name suggests, Sitecore Command Line Interface (CLI) is a command-line tool named Sitecore, and you add subcommands and options to accomplish different tasks. The Sitecore Command Line Interface is a new tool that was created to improve the Developer Experience with Sitecore 10. And specifically, for usage with serializing Sitecore items.
It can be used for serialization, creating item packages, and for publishing. No license is required, you just have to install it and start using it. So, on one side we have the CLI to interact with a Sitecore environment.
A big advantage is that you can use these tools to fetch items from a Sitecore website on another environment. So as a developer, we can more easily fetch items from an acceptance environment for example:
Please follow the below steps for installation.
If you have not already done CLI, install Sitecore Management Services.
Open a terminal with administrator privileges.
Go to the project folder and run the below commands.
dotnet new-tool manifest
dotnet nuget add source -n Sitecore https://sitecore.myget.org/F/sc-packages/api/v3/index.json
dotnet tool install Sitecore.CLI
To initialize your new project, run the following command in your project folder:
dotnet sitecore init
Install the required Publishing and Serialization plugins:
dotnet sitecore plugin add -n Sitecore.DevEx.Extensibility.Serialization
dotnet sitecore plugin add -n Sitecore.DevEx.Extensibility.Publishing
To verify that the Sitecore CLI works, go to your project folder in a terminal and type
dotnet Sitecore –version
Currently I am using 4.2.0.
To use Sitecore CLI, login is required and there are two ways to verify user verification.
Use an interactive user login
Use a non-interactive client login
1) Use an interactive user login
Please run the below commands in console.
Command: dotnet Sitecore login –authority https://<Sitecore identity server>–cm http:// <Sitecore instance> –allow-write true
Once the above command is fired it will open the login screen in the browser.
2) Use a non-interactive client login
To enable non-interactive client logins using client credential flows with your Sitecore instance, you must add additional configurations to your Identity Server and Content Management instances.
To configure a non-interactive client login:
On the Sitecore Identity Server, in the Config/ folder, create a file named Sitecore.IdentityServer.DevEx.xml containing the following:
Name the <CliServerClient> element anything that you like.
In the <ClientId> element, enter the unique ID of your client.
In the <ClientSecrets> element, create a <ClientSecret1> element containing the secret of your client.
Save the Sitecore.IdenityServer.DevEx.xml file.
On the Sitecore Content Management server, in the App_Config/Include/ folder, create a file named Sitecore.Owin.Authentication.ClientCredentialsMapping.config containing the following:
In the <claim name="client_id"> element, in the value attribute, enter the unique ID of your client.
Check your SQL Membership provider in the web.config file. If the solution has the requiresUniqueEmail attribute set to true, add the following configuration line to the Sitecore.Owin.Authentication.ClientCredentialsMapping.config file:
Save the Sitecore.Owin.Authentication.ClientCredentialsMapping.config file.
Restart the Sitecore Identity Server and the Content Management roles.
Recycle the Sitecore Identity Server application pool.
Validate your configuration by performing the client login procedure.
Command: dotnet sitecore login --authority https://<sitecore-identity-server> --cm http://<sitecore-instance> --allow-write true --client-credentials true --client-id <client-id> --client-secret <client-secret
After login, you are ready to serialize (push, pull) and publish the database via the below commands.
For serializing any Sitecore items, you can install and configure Sitecore CLI by following the above-given steps.