How to create custom scaffold templates in ASP.NET MVC5?

.net-4.0, asp.net-mvc, asp.net-mvc-5, asp.net-mvc-scaffolding, scaffolding

Solution

First, it looks like you have Visual Studio 2013 and 2012 both installed on your computer. I tried looking up the path you provided, I couldn't find it. On your path it looks like you're trying to use MVC4 templates. Here is my path:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\
Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates

Below is how I customized my scaffold template for the BaseController:

Create folder called "CodeTemplates" directly in the project folder.

Go to below path, find MvcControllerWithActions folder copy all to folder "CodeTemplates"

C:\Program Files (x86)\Microsoft Visual Studio 12.0\
Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates

Go to CodeTemplates -> MvcControllerWithActions in your project.

There are two files, `Controller.cs.t4` and `Controller.vb.t4` in MvcControllerWithActions, if you used C#, you can delete `Controller.vb.t4`.

Open the `Controller.cs.t4` file, modify the Controller name to BaseController, like below:

public class <#= ControllerName #> : BaseController
{
}

Now, when you try to create MVC5 Controller using "add new scaffold item", it'll use the template you customized.

Hope it helps.

Problem

I'm using ASP.NET MVC5 and VS2013 I've tried to copy CodeTemplates folder from C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\VWDExpress\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates with subfolders "AddController", "AddView" and T4 templates inside them, then I modified some templates, but nothing happened when I tried to add View nor Controller..

Original source