Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom "One ASP.NET" Project Templates within Visual Studio 2013

Goal:

Integrate project templates within Visual Studio 2013's "One ASP.NET" collection.

New ASP.NET Project with Fake Custom Template


Background:

The "to be distributed" project began as a new ASP.NET Web Application project, using the Empty template and the MVC and Web API "folders and references" checked. From there I added my love and affection and used Export Template. The zip lands in My Documents > Visual Studio 2013 > My Exported Templates. If you have Visual Studio install the template for you, a duplicate zip is placed within My Documents > Visual Studio 2013 > Templates > ProjectTemplates. Here's where the problem begins...


Issue:

In Visual Studio the template is found within the Visual C# tree branch, not a custom template within the ASP.NET Web Application template. Bummer. Even more odd, the template installs only to C# and not to its Web sub-folder.

MSDN documentation online mentioned a <ProjectSubType> within the .vstemplate file, which was empty when I investigated, but even explicitly adding Web did not change the UI location. This nothing to do with my goal really, but it seems to suggest that VS2013 does not honor some of the XML within .vstemplate?

More Info:

I started digging through the Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ProjectTemplates\ and one of the oddball things I noticed was two separate "folder trees": {root}\Web\CSharp\1033 and {root}\CSharp\Web\1033.

The first tree held WebTemplate45 and its project WebApplication45Dev12.vstemplate illustrating the ProjectType and ProjectSubtype values mentioned above. Mimicing this did not change aything.

The second tree also held a WebTemplate45 with WebTemplate.vstemplate included. This one was was significantly different because its Type=ProjectGroup and it referenced a TemplateGroupID and curious WizardExtension tag that referenced the OneASPNetProjectTemplateWizard. My guess is this is the daddy template that displays those showen in the image displayed.


Question(s)

What does it take to deliver a project package in the "One ASP.Net" popup? Registry alterations? VSIX?

If it is not possible, is there anyway to clone the daddy window for all custom projects? Ex. imagine the window displayed with only a company's child templates listed.


References:

http://msdn.microsoft.com/en-us/library/xwkxbww4.aspx

http://www.asp.net/mvc/tutorials/mvc-4/custom-mvc-templates

like image 343
one.beat.consumer Avatar asked Mar 25 '14 22:03

one.beat.consumer


People also ask

How do I create a new dotnet template?

To do that, execute the command dotnet new --install <PATH> where <PATH> is the path to the folder containing . template. config . When that command is executed it will discover any template files under that path and then populate the list of available templates.

How do I create a new MVC project in Visual Studio 2013?

To create new project, Open Visual Studio, I am using Visual Studio 2013 and click on File Menu, then New and choose Project. It will open a new window from where you can choose the application type. Choose Web from Installed and then choose ASP.NET Web Application.


1 Answers

Have you seen the Hot Towel MVC sample from John Papa? http://visualstudiogallery.msdn.microsoft.com/1eb8780d-d522-4dcf-bf56-56f0eab305c2

Opening the VSIX file in WinRAR, the key bits, in HotTowelSpa.2013.vsix\ProjectTemplates\HotTowelSpaProjectTemplate.cshtml\HotTowelSpaProjectTemplate.cshtml.vstemplate, seem to be:

<ProjectType>CSharp</ProjectType>
<ProjectSubType>Web</ProjectSubType>
<TemplateGroupID>Web</TemplateGroupID>

Edit

Indeed, it does look like you have to specify, specifically, that the project type is MVC: http://www.asp.net/mvc/tutorials/mvc-4/custom-mvc-templates

From the page:

The Type attribute of each element must be set to Microsoft.VisualStudio.Mvc.Template. This is a custom namespace that only the MVC project wizard understands.

Just adding the files to the VSIX is not sufficient to register the templates with the MVC wizard. You need to provide information such as the template name, description, supported view engines and programming language to the MVC wizard. This information is carried in custom attributes associated with the element for each vstemplate file.

Looking in extensions.vsixmanifest, I do indeed see <Asset ... ProjectType="MVC"... and the assets marked with Type="Microsoft.VisualStudio.Mvc.Template"

like image 98
Steve Andrews Avatar answered Oct 27 '22 00:10

Steve Andrews