Quantcast
Channel: Kev @ MVC » t4 template
Viewing all articles
Browse latest Browse all 8

Modify or Override the default t4 templates in MVC

$
0
0

When you create a new View or Controller in a mvc project. It is T4 templates to generate the piece of code for a new view or controller.

image

image

The templates are located in

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 3

or

C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 3

We can bring these templates to our local project by dragging the “CodeTemplate” folder to Visusal Studio from Windows File Explorer.

image

You will see some compilation errors, these will be fixed after you have clear all the templates’ property “CustomTool”. Just clear the string out.

You can add your own templates as well. Next time when you add a new view, or controller, you will see the project is using your local templates to create them.

This is very helpful and I have Learned this trick from Scott Hanselman.

Here is the blog entry from him, if you want to read more about it.

http://www.hanselman.com/blog/ModifyingTheDefaultCodeGenerationscaffoldingTemplatesInASPNETMVC.aspx



Viewing all articles
Browse latest Browse all 8

Trending Articles