Multi-Project Visual Studio Template Tricks
I've been knee-deep in Visual Studio project and item templates since the first version of Visual Studio, but this was the first time I needed to create a template that added multiple projects to a single solution...specifically, I wanted to create a better template for a Silverlight RIA client and associated Web host. This MSDN topic is a great place to start:
There were two situations this topic didn't cover. The first, was:
How do you specify which of the two projects is the Startup Project?
After a bit of trial and error, I discovered that the project listed first in the <ProjectCollection> element is set to the Startup Project by default. So, in the following example, My Windows Application would be set as the Startup Project
<ProjectTemplateLink ProjectName="My Windows Application">
<ProjectTemplateLink ProjectName="My Class Library">
How can I pass a customer parameter value to my sub projects?
This one took a little more trial and error. I found a post in a forum by a Microsoft tech support person that said you can't pass the vaue of custom parameters to sub projects by declaring the custom parameter in the root vstemplate file (I tried this and they were right!). However, I was able to get around this limitation by making use of a static variable. Here are my steps:
1. I created a custom Wizard Extension that collected a value from the user and stored the value in a static variable of that wizard class. If you're not familiar with Wizard Extensions, check out this topic: http://msdn.microsoft.com/en-us/library/ms185301.aspx
2. I declared the same Wizard Extension class for each of my subprojects. In all three templates (the root template and the subprojects) I declared a <WizardData> element that passes data to my custom wizard. This allows me to specify in the template that a project is a main project or sub project. If you're not familiar with the WizardData element, check out this link: http://msdn.microsoft.com/en-us/library/ms171415.aspx
3. In the sub projects, I checked the value of the static variable and, voila! It was available to my subprojects.
I hope this post helps out anyone who is looking to make the most of multi-project Visual Studio templates!
President, Oak Leaf Enterprises, Inc.
Home of the MM .NET Framework