This project is read-only.

VS2012 Multi project template with Wizard to collect user inputs

May 30, 2013 at 2:05 PM
Hi Folks,

How I can use nupattern to create a multi project template which displays a wizard to collect user input for project name and namespace.

How to define the project reference dependencies with nupattern

Any reference would be appreciated

Thanks Soni
May 30, 2013 at 11:15 PM
Hi Soni,

Multi-project templates are not ideal in NuPattern (that is: VS Templates with Type="ProjectGroup")
Instead, try combining multiple project templates (Type=Project) on the same element in your pattern model, or define multiple child elements in your pattern model which represent the individual content or intention of the template, and have the templates unfolded when they are instantiated.

An example of this is in the 6min video on the site home page. I think zteven can provide you with that source code too.

Your wizard will display (and store) the namespace and other properties defined on the element upon which you execute the wizard.
You can display your wizard as any of your templates are unfolded (i.e. on the same event as your templates are unfolded), and then use the value of the properties you collect in the wizard as substitutions in the files unfolded by your VS template. There are several examples of this around the place, and I think the Hands-On Labs demonstrates this as well too. This is standard VS template substitution except that NuPattern adds the values of all the properties of all elements in your pattern model as substitutions as well: i.e. $MyPattern.Property1$ or $MyPattern.MyChildElement.Property1$ or $Parent.Property1$

I am not sure I clearly understand your query about defining project references.
If you mean, how do you get an assembly reference in one of your unfolded projects? these are defined as line-items in in the *.csproj file in your VS template.
If you mean, how do you reference other projects that are unfolded, these are also line items in the *.csproj file in your VS Template.
(setup a couple of dummy projects up in Visual Studio, set the references the way you like it, and explore the XML content of the *.csproj files to see how that is done. Then make the adjustments in your VS template files).

Hope this helps, if not, I can give you more guidance.
Jun 19, 2013 at 12:01 PM
Hi guys,

I'm trying to create a multi project template which displays a wizard to collect user input (similar to Soni approach...).
I can't get good results even editing manually the .vstemplate (unfold launch point of my pattern) to force Type="ProjectGroup" and folder solution.
My PoC is using the following msdn sample:

<VSTemplate Version="3.0.0" Type="ProjectGroup"
    <Name>Multi-Project Template Sample</Name>
    <Description>An example of a multi-project template</Description>
        <SolutionFolder Name="Math Classes">
            <ProjectTemplateLink ProjectName="MathClassLib1">
            </ProjectTemplateLink ProjectName="MathClassLib2">
        <SolutionFolder Name="Graphics Classes">
            <ProjectTemplateLink ProjectName="GraphicsClassLib1">
            </ProjectTemplateLink ProjectName="GraphicsClassLib2">

What should be the best practice to achieve that?
Thanks for any kind of recommendation.
Jun 21, 2013 at 6:24 AM
Hi mosquet.

The first problem is that the XML you have gotten from MSDN is actually invalid. Its not a valid XML document!
It should look like this:
      <SolutionFolder Name="Math Classes">
        <ProjectTemplateLink ProjectName="MathClassLib1">MathClassLib1\MyTemplate.vstemplate</ProjectTemplateLink>
        <ProjectTemplateLink ProjectName="MathClassLib2">MathClassLib2\MyTemplate.vstemplate</ProjectTemplateLink>
      <SolutionFolder Name="Graphics Classes">
        <ProjectTemplateLink ProjectName="GraphicsClassLib1">GraphicsClassLib1\MyTemplate.vstemplate</ProjectTemplateLink>
        <ProjectTemplateLink ProjectName="GraphicsClassLib2">GraphicsClassLib2\MyTemplate.vstemplate</ProjectTemplateLink>
Once you fix this, and you add new project templates for each of the sub projects (MathClassLib1, MathClassLib2, GraphicsClassLib1, GraphicsClassLib2) then make sure you nest them in Solution Explorer within the muti-project template folder, rename the *.vstemplate filename to MyTemplate.vstemplate, and set their 'Build Action' to 'Content', 'Copy Output' to 'Copy if Newer' manually.) You can then add a Template Launch Point to unfold the template from your pattern element.

I have confirmed this works myself by creating a simple toolkit that did this and it works fine.

The second issue, as I told Soni, is that NuPattern does not support multi-project templates in that when your element is created, it will not be associated (connected to) any of the projects that get unfolded. As it normally does with single project template. It will create the solution and its structure fine, but you will have to link your element with an artefact link yourself.