Sitecore Helix dotnet CLI Templates

After exploring how to create a dotnet CLI new template for Sitecore docker projects, it seemed only natural a similar thing could be created to help support Sitecore Helix solutions.

Thus I have created and published two Helix related templates to NuGet called TheCodeAttic.Sitecore.HelixTemplates.

There exists two templates as part of the package. The first, sc-helixsln creates the Visual Studio solution, related folder structure and a few starting project and foundation projects. The second template, sc-helixmodule, creates the C# project and related folder structure for a new module project.

Credit to who its Due

Both the solution and module templates loosely based off the ever popular HelixBase project.

I have borrowed some of the basic structure from this project, but wanted a slightly simpler starting point without Glass and other services.

Some key elements:

  • Website project is included that leverages Helix Publishing Pipelines, parameters at creation exist to allow setting the publish target path
  • Projects are based on the .NET Core SDK Library style
  • Projects use NuGet PackageReferences
  • A sample AzureDevops build pipeline YAML is include to help quick-start your CI/CD process

To Create a New Solution

  1. Open a PowerShell prompt
  2. Change directory to your base code directory (ie: C:\Code)
  3. At the prompt enter, where
    1. "-n" represents the name of the directory as well as the solution name
    2. "–publishpath" is the fully qualified file path to the target location of a local code build.
dotnet new sc-helixsln -n TheCodeAttic.Adventures --publishpath C:\Code\TheCodeAttic.Adventures\docker\src

Sitecore.Helix.ModuleTemplate

To keep the solution simple and lightweight no Feature Modules have been included. These and additional foundation modules can be added by using the Sitecore.Helix.ModuleTemplate.

Add a Module to the Solution

  1. Open a PowerShell prompt
  2. Change directory to the module layer folder (ie: C:\Code\TheCodeAttic.Adventures\src\Feature)
  3. At the prompt enter, where
    1. "–projectname" is the first portion of the namespace, ie TheCodeAttic.Adventures.Feature.HeroImageDisplay
    2. "–layer" must be one of the following, Feature, Foundation, Project
    3. "–modulename" final portion of the namespace, what the module’s purpose is, ie TheCodeAttic.Adventures.Feature.HeroImageDisplay

Thus you can think of the paramaters as follows: "projectname.layer.modulename".

dotnet new sc-helixmodule --projectname TheCodeAttic.Adventures --layer [Feature, Foundation, Project]  --modulename HeroImageDisplay
  1. After running the new template command, you can return to Visual Studio.
  2. Create a solution folder within the appropriate layer
  3. Use the solution explorer context menu to add an existing project and select the one created in step 3.

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 )

Google photo

You are commenting using your Google 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.