简体   繁体   中英

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)

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

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

I dont found the template but i have maybe a solution but i have not tested yet on VS2015, you can get the MvcScaffolding nuget package https://www.nuget.org/packages/MvcScaffolding/1.0.9 by Scott Hanselman and Steve Sanderson. It's a bit old but working on VS2013.

And link about the package on steven sanderson blog http://blog.stevensanderson.com/2011/01/13/scaffold-your-aspnet-mvc-3-project-with-the-mvcscaffolding-package/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM