Sitecore Command Line Interface: Part-1

The Sitecore Command Line Interface is a new feature with Sitecore 10 and higher versions. It provides the ability to login into the remote Sitecore instance, serializes items, and publish, package, and additional commands reference for the command line.

I have divided this blog post series into the below section:

  1. Configure Sitecore CLI on the workstation
  2. Sitecore Content Serialization with CLI
  3. Sitecore Content Serialization with Visual Studio

You may have seen several blog posts, and videos on the same, but in this blog, I will make it easier for you and you do not need to set up the Sitecore project using Helix-base or getting a start template. In the first blog of the series, I will let you know about configuring Command Line Interface on the developer workstation. Once it will configure you can utilize another tool with Sitecore which is Content Serialization using CLI and Visual studio.

Sitecore Command Line Interface (CLI) allows console communication with a Sitecore instance. sitecore-command-line-1

Prerequisite to be installed on developer machine:

  • Sitecore 10+ instance
  • Sitecore.ManagementServices package.
    To install Sitecore Management Service in CM Download the Sitecore.ManagementServices package file from the Sitecore Downloads site. On the Sitecore Launchpad, click Control Panel, and Install a package. Then follow the Installation Wizard to install the Sitecore.ManagementServices package file.
  • .NET Core

Install Sitecore CLI:

Create a project folder and open a terminal in the project folder with administrator privileges.

Run the following commands:

  1. dotnet new tool-manifest

    It will create Dotnet local tool manifest file named dotnet-tools.json in the .config folder.

    sitecore-command-line-2

    When you use a CLI command that refers to a local tool, the SDK searches for a manifest file in the current directory and parent directories. If it finds a manifest file, but the file doesn't include the referenced tool, it continues the search up through parent directories. The search ends when it finds the referenced tool or it finds a manifest file with isRoot set to true.

  2. dotnet nuget add source -n Sitecore https://sitecore.myget.org/F/sc-packages/api/v3/index.json

    It will add a package source with the name .sitecore.

  3. dotnet tool install Sitecore.CLI

    It will install the  'sitecore.cli' tool and entry is added to the manifest file.

    sitecore-command-line-3

    To install the CLI globally, use the -g option when running the install command (not recommended).
    Other developers working on the same project only need to run dotnet tool restore to install Sitecore CLI.

  4. Initialize your project, and run the following command in your project folder.

    dotnet sitecore init

    Sitecore.DevEx.Extensibility.Serialization
    Sitecore.DevEx.Extensibility.Publishing
    Sitecore.DevEx.Extensibility.Indexing
    Sitecore.DevEx.Extensibility.ResourcePackage

    The command Sitecore init creates Sitecore configurations in the current directory and adds default plugins with the same version as the CLI to the sitecore.json file. The plugins are Sitecore.DevEx.Extensibility.Serialization, Sitecore.DevEx.Extensibility.Publishing, Sitecore.DevEx.Extensibility.Indexing, and Sitecore.DevEx.Extensibility.ResourcePackage.

Verify the installation:

You can execute the below two commands and verify the outputs to check that installation is done successfully or not on your machine.

dotnet sitecore –h

sitecore-command-line-4

dotnet sitecore plugin list

sitecore-command-line-5

After successfully configuring the CLI on your machine you are ready to use the other CLI tools. I am providing you with my project folder structure to have a better idea to start.

sitecore-command-line-6

In the next blog, I will discuss Sitecore Content Serialization using CLI.

Happy Sitecoreing ðŸ˜Š

Comments

Popular posts from this blog

Sitecore Installation Error: Failed to Start Service 'Sitecore Marketing Automation Engine'

Import CSV Data in Sitecore Using PowerShell: Part-3

Sitecore Technology MVP Journey 2022