Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize ASP.NET MVC 5 scaffolding in VS 2015?

I am developing an ASP.NET MVC 5 project. (not ASP.NET 5). Recently I switched to VS 2015. Now I decided I would like to create customized scaffolded Views and Controllers for my EF entities. So I searched and found Scott Hanselman's article about this topic. (It is obviously old). I've checked the folder Hanselman refers to:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC X\CodeTemplates\

While it exist in my VS 2013 installation it does not exist in my VS 2015 installation.

More diagnostics, and what I've done so far:

  • Scaffolding (the default) is working in my VS 2015 installation (but where the templates coming from?)
  • I've searched my whole VS 2015 installation folder for *.tt nothing found except EF context generators
  • I've tried to find more recent articles, but they either old, either talking about scaffolding in ASP.NET 5 (vnext) projects.

I would like to customize scaffolding Controllers and Views in my ASP.NET MVC 5 project using VS 2015. Ideally I would like to do this at project level, not globally overwriting developer machine level the templates. (as Hanselman's method allows it)

Any ideas or alternative mode to generate custom views and controllers based on EF entities (not starting from ground zero and reinventing the wheel)

like image 518
g.pickardou Avatar asked Aug 12 '15 07:08

g.pickardou


2 Answers

ASP.NET MVC 5 stores the scaffolding templates in the Common7\IDE\Extensions\Microsoft\Web\Mvc folder, both in Visual Studio 2013 and Visual Studio 2015. I found this thanks to Imran Baloch's post on customizing the Web API 2 templates.

Instead of version specific folders, there is a separate folder per template type that includes a version number

like image 176
Panagiotis Kanavos Avatar answered Sep 17 '22 11:09

Panagiotis Kanavos


For visual studio 2015 the path to the templates have changed notice the 14 and web

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

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

like image 45
Transformer Avatar answered Sep 20 '22 11:09

Transformer