简体   繁体   English

如何在VS 2015中自定义ASP.NET MVC 5脚手架?

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

I am developing an ASP.NET MVC 5 project. 我正在开发一个ASP.NET MVC 5项目。 (not ASP.NET 5). (不是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. 最近我转到了VS 2015.现在我决定为我的EF实体创建自定义的脚手架视图和控制器。 So I searched and found Scott Hanselman's article about this topic . 所以我搜索并找到了Scott Hanselman关于这个主题的文章 (It is obviously old). (显然很老)。 I've checked the folder Hanselman refers to: 我检查了Hanselman所指的文件夹:

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. 虽然它存在于我的VS 2013安装中但它在我的VS 2015安装中不存在

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?) 脚手架(默认)在我的VS 2015安装中工作(但模板来自哪里?)
  • I've searched my whole VS 2015 installation folder for *.tt nothing found except EF context generators 我搜索了我的整个VS 2015安装文件夹, 除了 EF上下文生成器之外没有找到* .tt
  • I've tried to find more recent articles, but they either old, either talking about scaffolding in ASP.NET 5 (vnext) projects. 我试图找到更多最近的文章,但它们要么旧,要么谈论ASP.NET 5(vnext)项目中的脚手架。

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. 我想使用VS 2015在我的ASP.NET MVC 5项目中自定义脚手架控制器和视图。理想情况下,我想在项目级别执行此操作,而不是全局覆盖开发人员机器级别的模板。 (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) 基于EF实体生成自定义视图和控制器的任何想法或替代模式(不是从零开始并重新发明轮子)

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. ASP.NET MVC 5将脚手架模板存储在Visual Studio 2013和Visual Studio 2015中的Common7\\IDE\\Extensions\\Microsoft\\Web\\Mvc文件夹中。我感谢Imran Baloch关于自定义Web API 2模板的帖子

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 对于visual studio 2015 ,模板的路径已经改变了注意14和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 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. 我没有找到模板,但我可能有一个解决方案,但我还没有在VS2015上测试过,你可以通过Scott Hanselman和Steve Sanderson获得MvcScaffolding nuget包https://www.nuget.org/packages/MvcScaffolding/1.0.9 It's a bit old but working on VS2013. 这有点旧,但在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/ 关于史蒂文桑德森博客上的软件包的链接http://blog.stevensanderson.com/2011/01/13/scaffold-your-aspnet-mvc-3-project-with-the-mvcscaffolding-package/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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