Let’s Talk

We would love to hear from you. Want to know more about
our services or have any questions? Say Hi!

How to install and configure Sitecore CLI?

February 09, 2023
How to install and configure Sitecore CLI?
Keyur Garala
Keyur Garala
Sitecore Certified Solutions Architect
how-to-install-and-configure-sitecore-cli

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.

  1. TDS

  2. UNICORN

  3. SITECORE CLI

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 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:

Sitecore CLI installation

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

    how-to-install-and-configure-sitecore-cli-1

    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.

how-to-install-and-configure-sitecore-cli-2 how-to-install-and-configure-sitecore-cli-3 how-to-install-and-configure-sitecore-cli-4

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:

  1. On the Sitecore Identity Server, in the Config/ folder, create a file named Sitecore.IdentityServer.DevEx.xml containing the following:

    how-to-install-and-configure-sitecore-cli-5
  2. Name the <CliServerClient> element anything that you like.

  3. In the <ClientId> element, enter the unique ID of your client.

  4. In the <ClientSecrets> element, create a <ClientSecret1> element containing the secret of your client.

  5. Save the Sitecore.IdenityServer.DevEx.xml file.

  6. On the Sitecore Content Management server, in the App_Config/Include/ folder, create a file named Sitecore.Owin.Authentication.ClientCredentialsMapping.config containing the following:

    how-to-install-and-configure-sitecore-cli-6
  7. In the <claim name="client_id"> element, in the value attribute, enter the unique ID of your client.

  8. 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:

    how-to-install-and-configure-sitecore-cli-7
  9. Save the Sitecore.Owin.Authentication.ClientCredentialsMapping.config file.

  10. Restart the Sitecore Identity Server and the Content Management roles.

  11. Recycle the Sitecore Identity Server application pool.

  12. 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.

how-to-install-and-configure-sitecore-cli-8
Conclusion

For serializing any Sitecore items, you can install and configure Sitecore CLI by following the above-given steps.


YOU MAY ALSO LIKE