This is where it gets fun. Let’s talk about some ways to ease your life when working with an Enterprise Layer via scaffolding automation.
By the way- this series assumes that you’re ready to embrace automation. I recommend you install Sitecore PowerShell extensions on all Sitecore environments, from local development up through production. For production usage, please refer to the Sitecore Powershell Extensions documentation on hardening. Take note that you don’t technically need this module in production, but I create power user scripts to drastically ease content maintenance. I’m also writing this from the perspective of the SCORE accelerator, but SXA does have similar automation with Powershell. I highly encourage you to extend and flex the system, regardless of the accelerator you select!
Adding new Helix Modules
As you probably know, working with Helix can be painful if you don’t automate the creation of projects. I recommend you take the time to explore a few of the options available to you, and select one that matches the way your team likes to work. Here are a few blog posts that I have found particularly useful in the past:
- Sitecore Helix with TDS: Create a new module with PowerShell by Una Verhoeven
- Habi what-a-tat? Create a Sitecore Helix solution from scratch using PowerShell by Akshay Sura
- Hands-on with Sitecore Helix: Using PowerShell to add a new module by Marc Duiker
There’s also a theme in the posts above, where developers are using Powershell to automate redundant tasks. As it turns out, Powershell is the secret to automation… and I love me some automation. If Powershell is not in your current repertoire, you should take the time to learn the basics of the syntax as well as explore Sitecore Powershell Extensions. I used to think Powershell was just a sysadmin tool, boy was I naive. I use Powershell nearly every day now, and my Sitecore experience has benefited tremendously from it. Go, learn it now!
Basics of Tenant Scaffolding
Scaffolding is formed of two parts: Visual Studio and Sitecore. Let’s talk about Visual Studio.
The SCORE Scaffolding can be downloaded even if you’re not using SCORE. If you download and open the Visual Studio Template, it looks like this:
Notice that there are a slew of files with the word
Rename.Me in their file name. There’s also a
scaffold.ps1 file. Hint: the ps1 extension is for powershell 😉
The idea is simple. Run the
scaffold.ps1 script, answer a few basic questions, and the script will proceed to find and replace the word
Rename.Me across all files within the directory. I encourage you to copy the SCORE scaffolding, and change it to represent what you want each of your tenants to look like.
For example, by default the SCORE solution utilizes NUnit for all unit testing. If your organization has standardized on a different library, like XUnit, then this is something you can customize for your version of scaffolding. Simply adjust the projects and their references as needed.
This solution template also assumes that you have specific environments (INT, QA, Production), but you can also change this to align with your organization. If you start to update the build profiles, you may want to grep your file system (e.g.,:
grep -irl int-single .) and find all usages of those tokens. They’re sprinkled not only throughout the C# projects, but also the TDS projects as well.
Be warned that you cannot open the
Rename.Me.sln file in Visual Studio, as Visual Studio may corrupt some of the scaffolding tokens.
I recommend checking this scaffolding script into source control as is. Then, through the magic of source control, you can track each element you’re adjusting as you make your adjustments to ensure you didn’t accidentally tweak something you didn’t mean to. You can also setup your README.md to have predefined installation instructions for your other developers who pull down and use each tenant. Remember, the lead developer scaffolds the solution and checks it into source control, each other developer checks out that solution and can then setup what the lead developer has on their machine.
A few considerations…
If you watched the Scaffolding video, you’ll notice that Brian installed Sitecore into a sandbox directory that was local to the git repository. This may feel weird at first, but the reasoning behind this is simple: separation of concerns. We want to keep our local development environments segregated for implementation. This helps with speed, being able to destroy and re-setup a tenant quickly, and helps you context switch in and out of tenants easier. This is debatable, but it’s how I like to approach things.
Another completely valid approach is to symlink your sandboxes together. Think of a symbolic link as a directory shortcut, except Powershell and TDS are able to navigate it as if it were a folder. In using symlinks, you can install Sitecore into one location and symlink all local sandboxes to that same location! This is incredibly useful for production support teams where they want to replicate a bug which may be difficult to track across multiple solution layers.
To symlink two directories together, open a command prompt and use a command similar to this:
mklink /J C:\path\to\local\sandbox C:\path\to\sitecore\installation
Tenant Structure Automation
As for the Sitecore side, Powershell is also the answer. I don’t want to get into the weeds of what the script is doing, the source code is out there and available for you (it’s a part of the SCORE Scaffolding download). Instead, I want to show you at a high level what must be done. To pull this off, there are a few things you need to know:
- The Tenant Scaffolding Automation script is available for download alongside the Visual Studio template.
- The scaffolding script is a Sitecore Powershell script. It installs into the Developer tab in the desktop, and when executed prompts you for a Tenant name. You can see the script contents from here:
/sitecore/system/Modules/PowerShell/Script Library/SCORE/Create SCORE Site
- Note: If you’re not using SCORE, you will be missing specific SCORE templates which this script assumes are available. You will be able to install it, just not execute it.
- You can also open the package up in 7zip and begin drilling down through directories. You’ll eventually hit an XML file that represents the serialized script item. It has the script inside of it.
- This Sitecore Powershell script executes a series of branch templates to create a new tenant, using the Tenant name provided.
- After the tenant is created, the script creates elements such as Custom Rules (e.g., Placeholder Setting Rules, Component Datasource Location Rules, etc), and establishes the Homepage and any tenant settings/selections/etc.
You can see those branch templates installed in the Branches area when you’re using SCORE:
If you’re using SCORE for your enterprise, you can take the SCORE Tenant Scaffolding Automation script and create a copy of it, along with a copy of the SCORE Scaffolding branch templates and tweak them as needed. The idea is that your Enterprise Layer could introduce any number of customizations, such as:
- Define special page types that should come with each tenant (such as a News Article Page or Product Detail Page)
- Define special settings items that each tenant would require (e.g., Form settings)
- Define special placeholder settings to allow pages to obtain Enterprise Components alongside Accelerator components
- Reorganize the tenant content tree into how you want your tenants to be organized.
I personally like to take the Sitecore portion of scaffolding and check it into my Enterprise Layer. Here’s what I recommend you do:
- Copy the SCORE Scaffolding powershell script and begin tweaking it.
- Store it in your Enterprise Layer under a Helix Project level module (which is dedicated to scaffolding). I would set it up so that only Administrators can see this button.
- Set it up so that it’s a button available under the Developer tab. To do this, store it in the Master database at: /sitecore/system/Modules/PowerShell/Script Library/Enterprise/Project/Content Editor/Ribbon/Developer/<Your Company>/New Site. By convention, Sitecore Powershell will create a new site button for you at the desired location. If you don’t see it, you may need to rebuild integration points.
- Package and distribute this button with your enterprise layer.
That should get you something like this:
From there, it’s easy to create as many tenant sites as you need. Each can have it’s own development team behind it, or one team can manage multiple. It depends on your organization:
Putting it all together
To recap the series up to this point- here’s what we’ve set up so far:
- We’ve picked an accelerator for Sitecore. In my case, I’m using SCORE.
- We’ve created a new solution which exists solely to create components and features that are specific to our enterprise. This is modeled after Helix.
- Each tenant (aka website) will receive its own solution, which is modeled after this blog series.
- To ease the setup of each tenant solution, we’ve created a visual studio template that can be setup in a matter of minutes with powershell.
- We’ve captured our basic tenant site structure as a series of branch templates.
- We’ve created a Sitecore Powershell Extensions module which can execute those branch templates strategically to generate a new tenant website.
Again, I want to reiterate that this is not an overnight transformation. What I’m showing you here is the end-state you want to be in. Even when knowing exactly what to do, this would take a week or two to setup fully- so prepare accordingly. Hope this helps!