Add the Sitecore CLI to the Windows Software Center
20 Nov 2024
Enterprises with a Sitecore CMS subscription will likely employ developers who need to invoke the Sitecore CLI (a .NET CLI tool) from their own workstations.
- In a perfect world, the enterprise has a vested interest in packaging the Sitecore CLI into the Windows Software Center for easy installation on a developer’s computer and keeping that installation up-to-date.
- In the real world, the developer needs to be able to use an antique version of the Sitecore CLI to communicate with an older Sitecore CMS.
Luckily, both needs can be met.
The enterprise can provide developers an always-latest-and-greatest version of the Sitecore CLI available through the Windows Software Center (as a “sitecore
command”) in a way that still lets developers also use older versions as needed for one-off issues (as a “dotnet sitecore
” command).
Here’s what the enterprise’s desktop software support team can program the Software Center to do when staff want to use it to install the Sitecore CLI onto their computers as a “sitecore
” command:
TODO – completely rewrite this or remove
TODO: maybe remove this post.
I’m not sure it’s actually useful to be able to run sitecore
instead of dotnet sitecore
, especially if you’re using tools that work on top of it like Sitecore for Visual Studio (“SVS”) and might be hardcoded to invoke dotnet sitecore
.
Software Center responsibilities
Create a distinctly named folder
Upon installation, have the Software Center create a folder that you feel confident won’t ever be used for anything else.
For purposes of this article, I’ll refer to it as C:\TheSitecoreCli
in code examples.
You’ll, of course, want to replace that with whatever folder name you chose when programming the Software Center to following my instructions.
(Upon uninstall, you’ll probably want the Windows Software Center to remove this folder as part of your cleanup.)
Add the new folder to the PATH environment variable
Have the Software Center append the new folder (e.g. C:\TheSitecoreCli
) to the machine’s – or to the user’s – PATH
environment variable if it’s not there.
(Or remove it if this is an uninstallation.)
Install, update, or uninstall the Sitecore CLI tool
Have the Software Center install the Sitecore CLI:
dotnet tool install 'Sitecore.CLI' `
--tool-path 'C:\TheSitecoreCli' `
--add-source 'https://nuget.sitecore.com/resources/v3/index.json'
Or update it, if that’s more appropriate:
dotnet tool update 'Sitecore.CLI' `
--tool-path 'C:\TheSitecoreCli' `
--add-source 'https://nuget.sitecore.com/resources/v3/index.json'
Or uninstall it, if that’s in order:
dotnet tool uninstall 'Sitecore.CLI' `
--tool-path 'C:\TheSitecoreCli'
Validate that the CLI runs
Both of these commands should return an appropriate version number if the Sitecore CLI tool has been correctly installed/updated into C:\TheSitecoreCli
by the Software Center.
(And, of course, after uninstall, these command invocations should error out.)
sitecore --version
C:\TheSitecoreCli\sitecore.exe --version
Software Center work done
That’s all there is to do, from a Software Center perspective.
The Sitecore CLI isn’t very useful without its various “plugin”-based subcommands.
However, unfortunately, those have to be installed repeatedly into each codebase folder on the developer’s workstation representing a given desired configuration state for the enterprise’s Sitecore CMS.
Only the developer knows exactly where they’ll want to put such a codebase, so the Software Center’s work is done.
Developer responsibilities
The developer can now run commands like these, as needed:
Plugin installation per codebase
Push-Location 'C:\DevelopersFavoriteFolder\'
dotnet new tool-manifest
sitecore init
sitecore plugin add -n 'Sitecore.DevEx.Extensibility.XMCloud'
Pop-Location
Codebase plugin validation
Once they do that in C:\DevelopersFavoriteFolder\
, then the following command:
Push-Location 'C:\DevelopersFavoriteFolder\'
sitecore plugin list
Pop-Location
Should return something like this:
List of plugins:
[Installed] Sitecore.DevEx.Extensibility.Serialization v.6.0.23
[Installed] Sitecore.DevEx.Extensibility.Publishing v.6.0.23
[Installed] Sitecore.DevEx.Extensibility.Indexing v.6.0.23
[Installed] Sitecore.DevEx.Extensibility.ResourcePackage v.6.0.23
[Installed] Sitecore.DevEx.Extensibility.Database v.6.0.23
[Installed] Sitecore.DevEx.Extensibility.XMCloud v.1.1.99
Validation that plugin installation scope is not too broad
But a command like either of these:
Push-Location 'C:\TheSitecoreCli\'
sitecore plugin list
Pop-Location
Push-Location 'C:\AnotherFolder\'
sitecore plugin list
Pop-Location
Should throw an InvalidConfigurationException
, complaining:
Couldn't find configuration file to resolve plugins, please specify correct config path or perform sitecore init command.
Couldn't resolve a root configuration file (sitecore.json) in the current or any parent directory. Looks like the command may have been executed outside a Sitecore project?
Happy developers, happy enterprise
Developers can now always run an up-to-date version of the Sitecore CLI by executing the sitecore
command, whenever that feels like the most appropriate version of the Sitecore CLI tool for them to run.
(Ahem – presuming the enterprise desktop support team programmed the Windows Software Center to keep all Sitecore CLI installations up-to-date on a regular schedule.)
However, because the Sitecore CLI isn’t installed as a conventional “global” .NET CLI tool that responds to dotnet sitecore
command invocations and instead has to be run via its .exe
file, it’s simple for developers to also install an older version of the Sitecore CLI into C:\WeirdSituationFolder
and run it locally in that folder like:
Push-Location 'C:\WeirdSituationFolder'
# Should return the recent version number
# managed by the Software Center:
sitecore --version
# Should return an older version number
# as chosen by the developer:
dotnet sitecore --version
# Presuming the dev also repeated
# the plugin installation steps
# from above within this folder,
# this command may show older plugins
# compatible with the older
# Sitecore CLI version they chose:
dotnet sitecore plugin list
Pop-Location
Additional links
- Official documentation - Sitecore CLI
- Scott Gillis - Quick start to the Sitecore CLI