Have you ever:
- Built a code library that only works if there’s certain Items in certain places in a Sitecore database?
- Wished you could force the existance of a certain Item or tree structure in a Sitecore database and restore it if it gets broken?
If so, then Constellation.Foundation.PackageVerification is the component for you!
How Does it Work?
It uses a very small Pipeline Processor to install Sitecore *.zip-type packages behind the scenes. The processor runs on the Sitecore
Initialize pipeline, along with a configuration file. You supply the packages, Verifier makes sure they’re installed the next time you reset the app pool.
The Verifier runs when Sitecore loads up from a cold start. It inspects the databases you specify, looking for Packages that should be installed, and installs them if they are not. Please note that these packages must be of the package.zip file variety, not the *.update package variety.
In Visual Studio, use the Package Manager console to install it into your Web Application project:
PM> Install-Package Constellation.Foundation.PackageVerification
There is an example configuration file at:
It supplies all the obvious details, however here’s a quick rundown.
Configuring Package Verifier
- Create your Package, It should only include Sitecore Items, no code, use NuGet for that. (In theory code and files are fine, but I haven’t tested it.)
- Note the IDs of key “root level” Items that are included in your package, you’ll need them to determine the current installation condition. I recommend including one ID for each “branch” created by your package, this might be a Template, a Rendering, and maybe a few content items. Include Items that must exist for your code to work, and ideally items that cannot be modified by end users. Don’t forget to include Items from every database touched by your package!
- Import your Package into your Visual Studio web application project. For Sitecore 9, the path in the project needs to be:
- Make sure your package Build Action Property in Visual Studio is set to “Content”. (otherwise, it won’t be there when your solution is deployed)
- Use NuGet to install the Package Verifier (see above)
- Make a copy of the supplied config file (above) and remove the
- In the config file, replace the example
<package />element examples with your own package definitions:
nameattribute can be anything, it is used in the log file.
packageFileNameattribute should match the name of the file on disk.
- For each of the “root level” IDs you noted in step 2, create an
<artifact/>element specifying the ID of the Item to look for and the database where it’s located.
- Make sure your new *.config file is also set to Build Action = “Content”.
- Build and Deploy!
- Check the log.txt on your installation. As long as it is set to “Info” level, you will see log entries for Package Verifier as it goes through each package you’ve defined in the config. Use the log to troubleshoot misspellings or failure to deploy.
Use Your Own Config Files
Constellation uses Sitecore Helix principles. You should never modify stock *.config files supplied with Constellation. They will be overwritten should you ever have to install an update via NuGet. Use Sitecore’s best practice for configuration patching and create your own patch files to modify Constellation from its default behavior.
I Want to See More
Fine, go grab the source code: