Unfolding Multiple Projects using Blueprints
In this blog we will see how to unfold multiple projects using Microsoft Blueprints. Unfolding default project or single project is quite easy. We will start with default and single project first and then see what extra needs to be done for multiple projects.
When user selects blueprint which he/she needs to use and clicks unfold, .Net project gets unfolded in current solution. By default the structure of this unfolded project looks as follows
How to specify this unfolded project according to our requirements? We will see this today where we will first unfold single project using blueprints and then extend it to unfold multiple projects.
To specify your own project template for blueprint, right click on Blueprint project and click “Edit Configuration” menu. You will see input “Template” here. By default value selected is “Auto-generated”.
You can choose option “User supplied” which allows you to specify which project template to be used for unfold action. Name of template file can be then entered in “Template” input textbox.
To create template file we will use utility provided by Visual Studio itself. Open the project for which template has to be created and select Menu File -> Export Template. This will create corresponding template for project and put it in folder “My Documents\Visual Studio 2008\My Exported Templates”
Suppose we have created template for Windows Application project, and name of template file is “WindowsApp.zip”. Copy this file and put it Blueprint project’s “templates” folder.
Also make sure you have given same file name for Template input using “Edit Configuration”.
Now Build Blueprint and see what it unfolds by opening another Visual Studio instance and using Blueprint manager. The unfolded project will be exactly same as what we have put in WindowsApp.zip template.
All menus with visibility “ThisProject” will be enabled for this unfolded project.
So we have successfully unfolded single project using blueprint. Steps were very straight forward and easy. Now let’s see how to unfold multiple project using blueprints. We will use already created project template “WindowsApp.zip” as first project template and will create new project template for class library say “ClassLib.zip”.
Now let’s target to unfold both these projects together using blueprints. Steps are as follows
- Make new folder “WinSols” in templates directory of blueprint.
- Unzip “WindowsApp.zip” and “ClassLib.zip” inside “WinSols” folder.
- Add file “MyTemplate.vstemplate” in “WinSols” folder.
- Edit file “MyTemplate.vstemplate” so that it contains information which projects to unfold when this template is used. We will use “ProjectCollection” tag to specify multiple projects. File will look like this
- Now select all files in “WinSols” folder by selecting “MyTemplate.vstemplate” first and say “Add to Zip”.
- Zip file “WinSols.zip” will be created. Put this file in templates folder of Blueprints which should be visible from Solution Explorer too.
- Specify now “Winsols.zip” as template file name using “Edit Configuration” dialog of blueprint.
- Rebuild blueprint and see what it unfolds now using second visual studio instance and Blueprint Manager. Unfolded projects look like
But now if you right click on any of above projects, you won’t be getting menu “Blueprints”. But this is not desired as then it loses main purpose of blueprints as workflow attached with blueprint is not accessible at all. Now here is a trick how to achieve this.
In steps we listed above for unfolding multiple projects, when you finish step 2 where we unzipped our multiple templates follow steps given below so that those projects get right click menu “Blueprints”.
- When you build blueprint project, build action creates file “StartupGUID.xml” in properties folder of blueprint. Note that this file is not visible in solution explorer and you need to browse for it in Windows explorer.
- Open this file and you will see entry as follows
Now this GUID is mainly used to associate unfolded project with specific blueprints. This only decides what menu should be available on unfolded project.
- Copy above ProjectExtensions tag and put it in both projects .csproj file. At the end (i.e. Classlib\Classlib.csproj and WindowsApp\WindowsApp.csproj). For this you need to open these files using Notepad.
- Once you modified .csproj files repeat steps explained above from 3 and see if you are getting menu “Blueprints” now on unfolded projects. And all blueprint menus having “ThisProject” visibility will be available for them.