views:

70

answers:

2

Hi,

ASP.NET MVC has a bunch of custom item templates to create controllers, views, etc. Those item templates appear to only show up in the Add New Item dialog box when you are inside an ASP.NET MVC project (or more specifically when the MVC project type guid is in the .csproj file). How do they manage to do this? I've looked through the .vstemplate files and there doesn't appear to be anything related to the project type guid.

Thanks, Nathan

A: 

The logic for these is in the T4 templates.

The Add Controller and Add View dialogs both perform code generation that use T4 templates behind the scenes. These templates can be modified to customize the generated code from these tools. You can find the templates at the following location:

[Visual Studio Install Directory]\Common7\IDE\ItemTemplates[CSharp | VisualBasic]\Web\MVC\CodeTemplates\

Robert Harvey
The logic for source code within the controller or view file is in the T4 template, but I don't think the logic for when it's displayed within Visual Studio's Add New Item dialog lives within that file.
Nathan Roe
I think if you wade through the Visual Studio SDK long enough you will eventually find a way to customize the menus. Also, the ASP.NET MVC source is on Codeplex. I suspect their hook for these menus is in the MVC Installer.
Robert Harvey
+1  A: 

I believe I figured it out. It looks like the TemplateGroupID node in the .vstemplate file specifies the name of the VS Project (as read from the registry) to show this template for.

Nathan Roe