When working with a Blueprint to deliver a product, we very often start with unfolding a solution/project structure (template) that reflects some architectural guidance. When building a Blueprint, we have a few options for unfolding templates within our Blueprint (that we can set through configuration as displayed below). The option ‘None’ obviously doesn’t unfold a template at all, ‘Auto-generated’ unfolds a predefined project template (C# class library) and ‘User-supplied’ provides us with the possibility to define our own solution/project templates. (The guidance that comes with the current release of Blueprints does a pretty good job describing these three options)
However, sometimes we need even more control before, during or after template unfolding (ie create folder structures, complex dialogs, Add to source control, etc.). Luckily, there is another mechanism that we can use for this scenario that gives us full control!
We can add a ‘Command Extension’ (right click on your Blueprint and select ‘Add Command Extension’ from the Blueprints menu) and write an extension that unfolds our custom project templates.
Adding a Command Extension to our Blueprint gives us a new project in our Blueprint solution. This new project already contains an example extension that we can modify to implement our custom unfolding logic. Below, a simplyfied implementation of this modified Command Extension is given that uses the custom ‘MyTemplate.vstemplate’ template and unfolds that to a (hard coded) location.
After we fully implemented our extension, we can add this Command Extension to the commands collection of our Blueprint (More info on how to add commands can be found in the Blueprints documentation).
The real ‘trick’ here is to name the command ‘INIT’ which will force the Blueprints Manager to execute the command automatically for us when unfolding our Blueprint to a (empty) Visual Studio solution. Also, don’t forget to set the ‘Template’ option in the Blueprint configuration dialog to ‘None’! Note that we also added a switch statement to our implementation of the Command Extension to only execute the template unfolding in case the ‘INIT’ command gets executed.
With this in place we can write complex ‘vstemplates’, that include WizardExtensions to collect user input and rely on the Blueprints Manager to execute our ‘INIT’ command to unfold these templates when developers add our Blueprint to their Visual Studio solutions.