[英]MVC Scaffolding with Custom T4 Templates in VS 2012 Express
Just getting started with customizing the generated MVC Controller / Views. 刚开始自定义生成的MVC控制器/视图。
Following Steven Sanderson's post: http://blog.stevensanderson.com/2011/04/06/mvcscaffolding-overriding-the-t4-templates/ 继史蒂文·桑德森(Steven Sanderson)的帖子之后: http : //blog.stevensanderson.com/2011/04/06/mvcscaffolding-overriding-the-t4-templates/
I used the Package Manager Console to generate 3 custom templates in my VS 2012 MVC4 project 我在VS 2012 MVC4项目中使用包管理器控制台生成了3个自定义模板
PM>Scaffold CustomTemplate View Create
PM>Scaffold CustomTemplate View Edit
PM>Scaffold CustomTemplate View _CreateOrEdit
which creates a the files in: CodeTemplates\\Scaffolders\\MvcScaffolding.RazorView _CreateOrEdit.cs.t4 Create.cs.t4 Edit.cs.t4 在以下位置创建文件:CodeTemplates \\ Scaffolders \\ MvcScaffolding.RazorView _CreateOrEdit.cs.t4 Create.cs.t4 Edit.cs.t4
But, when I "Add Controller" and choose the template Mvc Controller with read/write actions and views using Entity Framework 但是,当我“添加控制器”并使用实体框架选择具有读/写操作和视图的模板Mvc Controller时
The new templates are NOT being used ??? 新模板未使用???
I was able to modify the create.tt edit.tt templates with notepad in the VS 2012 folder and then generate with the changes in my project. 我能够使用VS 2012文件夹中的记事本修改create.tt edit.tt模板,然后在项目中生成更改。 C:\\Program Files\\Microsoft Visual Studio 11.0\\Common7\\IDE\\VWDExpress\\ItemTemplates\\CSharp\\Web\\MVC 4\\CodeTemplates\\AddView\\CSHTML C:\\ Program Files \\ Microsoft Visual Studio 11.0 \\ Common7 \\ IDE \\ VWDExpress \\ ItemTemplates \\ CSharp \\ Web \\ MVC 4 \\ CodeTemplates \\ AddView \\ CSHTML
Anyone know what I'm doing wrong ? 有人知道我在做什么错吗?
Thanks, LA Guy 谢谢,盖伊
Try creating a CodeTemplates\\AddView\\CSHTML
folder inside your solution and put your templates there (or CodeTemplates\\AddController
for a controller template). 尝试在解决方案内部创建CodeTemplates\\AddView\\CSHTML
文件夹,然后将模板放在此处(对于控制器模板,则放在CodeTemplates\\AddController
中)。 It worked for me in VS2012. 它在VS2012中对我有用。 These can be checked into source control and everyone can share them. 可以将它们检入源代码管理,每个人都可以共享它们。 The ones in your VS install directory are a bit harder to share. VS安装目录中的文件很难共享。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.