Create a MVC 3 web solution template – Part 2, Create VS template and grouping projects

From part 1, I have talked about my project template structure. Now I want to talk about how do I create the VS templates and group them into one solution.

Visual Studio only allow you to create a template from one single project. So we need to write some vstemplate scripts to group our projects all together into one solution. And save the below script as “Template.vstemplate”.

</pre>
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="ProjectGroup">
 <TemplateData>
 <Name>Web MVC 3 Template</Name>
 <Description>MVC 3 web application template</Description>
 <ProjectType>CSharp</ProjectType>
 <TemplateGroupID>MyApplication</TemplateGroupID>
 <NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
 <SortOrder>1000</SortOrder>
 <CreateNewFolder>false</CreateNewFolder>
 <DefaultName>MVC3Application</DefaultName>
 <ProvideDefaultName>true</ProvideDefaultName>
 <LocationField>Enabled</LocationField>
 <Icon>__TemplateIcon.png</Icon>
 <PreviewImage>__PreviewImage.png</PreviewImage>
 <EnableLocationBrowseButton>true</EnableLocationBrowseButton>
 <PromptForSaveOnCreation>true</PromptForSaveOnCreation>
 <RequiredFrameworkVersion>4.0</RequiredFrameworkVersion>
 </TemplateData>
 <TemplateContent>
 <ProjectCollection>
 <ProjectTemplateLink ProjectName="$safeprojectname$.Business">
 Business.Template\MyTemplate.vstemplate
 </ProjectTemplateLink>
 <ProjectTemplateLink ProjectName="$safeprojectname$.Web">
 Web.Template\MyTemplate.vstemplate
 </ProjectTemplateLink>
 <ProjectTemplateLink ProjectName="$safeprojectname$.Data">
 Data.Template\MyTemplate.vstemplate
 </ProjectTemplateLink>
 </ProjectCollection>
 </TemplateContent>

</VSTemplate>
<pre>

If you use “Export Template” wizard from VS, export all projects from your solution, and unzip them into one folder.

image_thumb

In my example I have three projects, Data, Business and Web. Here is the folder structure.

image_thumb1

Now zip all the files and folders into one single package. Put it into your Visual Studio template folder.

{Documents}\Visual Studio 2010\Templates\ProjectTemplates

Or change your template location to your folder. Open VS -> Tools -> Options -> projects and solutions

image_thumb4

Now if you open VS and create a new project, you can find the template under C# projects.

—————————————————————————————–

Download the sample vstemplate from http://mvc3projecttemplate.codeplex.com/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s