Sitecore Content Serialization Changes with CLI 4.0

Sitecore CLI 4.0 has been launched and with this new features appeared, such as plugins but also bugfixes/improvements.

To install it you need to edit or uninstall/install your old CLI in your solution with the new version.
Don’t forget to install the new Sitecore Management Services into your Sitecore instance Module which you can download from here!!!

The major changes are: Sitecore Roles, Exclude global/module specific fields, Sitecore publishing to specific targets, Sitecore Index plugin and Sitecore Resources plugin.

1. Sitecore Roles Introduced

I was really happy when I saw that from now on you can serialize the sitecore roles with Sitecore Content Serialization, similarly to Unicorn.
To serialize it you just need to extend your module where you want the roles to be serialized, for example the modules with roles:

{
"namespace": "Feature.Cars",
"items": {
"includes": [
{
"name" : "master/sitecore/templates/Feature",
"path" : "/sitecore/templates/Feature/Cars"
},
{
"name" : "master/sitecore/layout/Renderings/Feature",
"path" : "/sitecore/layout/Renderings/Feature/Cars"
}
]
},
"roles": [
{
"domain": "extranet",
"pattern" : "Cars*"
}
]
}

In the above example, serialization happens from the “extranet” domain with all of the roles following the “Cars*” pattern.

2. Exclude global/module specific fields

With the new release, we have the option of excluding fields from serialization. There are two options:

  • Exclude globally from all of the modules
  • Exclude just on specific modules

To exclude globally you need to add the configuration to your global sitecore.json file, to exclude locally you need to add it in your module configuration. The exclude configuration is really straightforward, you just need to specify the field ID and a description:

"excludedFields" : [
{
"fieldId" : "5dd74568-4d4b-44c1-b513-0af5f4cda34f",
"description" : "Created by"
}
]
view raw exclude.json hosted with ❤ by GitHub


For example, if you want to exclude a field from your entire serialization:

{
"$schema": "./.sitecore/schemas/RootConfigurationFile.schema.json",
"modules": [
"src/*/*/*.module.json"
],
"plugins": [
"Sitecore.DevEx.Extensibility.Publishing@4.0.0",
"Sitecore.DevEx.Extensibility.Serialization@4.0.0",
"Sitecore.DevEx.Extensibility.Indexing@4.0.0",
"Sitecore.DevEx.Extensibility.ResourcePackage@4.0.0",
],
"serialization": {
"defaultMaxRelativeItemPathLength": 120,
"defaultModuleRelativeSerializationPath": "serialization",
"excludedFields" : [
{
"fieldId" : "5dd74568-4d4b-44c1-b513-0af5f4cda34f",
"description" : "Created by"
}
]
}
}
view raw sitecore.json hosted with ❤ by GitHub

For example, if you want to exclude in a module:

{
"namespace": "Feature.Ships",
"items": {
"includes": [
{
"name" : "master/sitecore/templates/Feature",
"path" : "/sitecore/templates/Feature/Ships"
},
{
"name" : "master/sitecore/layout/Renderings/Feature",
"path" : "/sitecore/layout/Renderings/Feature/Ships"
}
],
"excludedFields": [
{
"fieldId" : "0d275dfa-dbb4-4e46-9df2-303f77b4541b",
"description" "Author"
}
]
}
}

3. Sitecore Publish to specific targets

You have the option from now on to publish to specific targets. From default is the web database. The command line for publishing:

dotnet sitecore publish --targets [target-names]

You have the option of publishing to multiple instances, for example:

dotnet sitecore publish --targets Web1, Web2

4. Sitecore Indexing plugin

The plugin was created to handle indexes.
Commands for the plugin:

4.1 List indexes:

dotnet sitecore index list

4.2 Populate Solr Managed Schema:

dotnet sitecore index schema-populate

4.3 Rebuild Indexes

dotnet sitecore index rebuild -indexes [list of indexes]

Example of the multiple index rebuild command:

dotnet sitecore index rebuild --indexes sitecore_master_index, sitecore_web_index

4.4 View Index statistic

dotnet sitecore index statistic

5. Sitecore Resources plugin

With the plugin you can create a new resource item package based on your Sitecore Contend Serialized items or you have the option of creating resource files based on your serialized items produced by Unicorn.
Command to create resource item package:

dotnet sitecore itemres create --output [output path] --include [modules to include] -- exclude [modules to exclude]

Example of the item resource creation command:

dotnet sitecore itemres create --output "D:\Itemresources\Master.dat" --include Feature.Ships --exclude Feature.Cards --overwrite

Command to create resource item package for Unicorn:

dotnet sitecore itemres unicorn --output [output path] --path [path to unicorn serialization folder]

These were the major changes, use them as much as you can:)

Have a great time coding, see you at my next post! 😀

Published by Gerhart Magdas

I'm a Sitecore developer since 2017 and Sitecore Technology MVP 2022

One thought on “Sitecore Content Serialization Changes with CLI 4.0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with WordPress.com
Get started
%d bloggers like this: