Use different module templates for feature and foundation projects when using add-helixmodule.ps1
The add-helixmodule.ps
In my first Sitecore Helix project I got introduced to a PowerShell script add-helixmodule.ps1This script has a few commands that you can call from the console inside Visual Studio:
- Add-Feature
- Add-Foundation
- Add-Project
The creator of this PowerShell script is Marc Duiker, for more info you can read about it in his blog post here.
Why have two different templates
After creating several feature and foundation projects, I wanted to extend the template to have more references and files in the feature projects. I did not want to add all of these changes when creating foundation projects.The solution
I solved this by creating two module template folders. One for Foundations and another for Features.In the Feature module template I added references to the foundation projects and added the files I wanted to be created when calling the Add-Feature command.
In the Foundation module template I removed the files we usually don't need there, and tried to make it as slim as possible.
Changes needed to make the commands use correct template folders
In the JSON file we have the following line:
"moduleTemplatePath": "C:\\yyy\\xxx\\module-template",
I created two new paths in the configuration:"moduleTemplatePath": "C:\\yyy\\xxx\\module-template",
"moduleFoundationTemplatePath": "C:\\yyy\\xxx\\module-template-foundation",
"moduleFeatureTemplatePath": "C:\\yyy\\xxx\\module-template-feature",
"moduleFeatureTemplatePath": "C:\\yyy\\xxx\\module-template-feature",
Changes to add-helixmodule.ps:
I changed the script so it would pick up the correct template paths. When using Add-Feature we would be using the moduleFeatureTemplatePath. When using Add-Foundation we would be using the ModuleFoundationPath.
Additional notes
If you end up with files and references you don’t use you should not add them, the templates are there to help you create the files and references that you need instead of adding them manually.We did update the feature template with more items during the development, introducing Glass Mapper and more.
We made minimal changes to the initial foundation template.
Comments
Remember to add moduleProjectTemplatePath to the add-helix-module-configuration.json file.