Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC 5 Custom Scaffolding Option [t4 templates]

Currently , I am developing a framework , I want to add custom scaffolding option in visual studio menu.

Custom scaffolding option

By default "MVC5 Controller with views, using Entity Framework" option 3 from the dialog box chooses "CodeTemplates\MvcControllerWithContext\Controller.cs.t4" , that t4 again targets view t4 templates inside

  • "CodeTemplates\MvcView\ModelMetadataFunctions.cs.include.cs.t4"
  • "CodeTemplates\MvcView\Create.cs.t4"
  • "CodeTemplates\MvcView\Edit.cs.cs.t4"
  • "CodeTemplates\MvcView\Delete.cs.cs.t4"
  • "CodeTemplates\MvcView\List.cs.cs.t4"

Visualization

I have been modifying t4 templates almost a year, I haven't found a single piece of evidence that suggest that how it is targeting those views or how to add option in the scaffolding dialog. I have googled a lot , however haven't found anything close.

In summary , I am only looking for the place where I can add or modify the locations for those t4 templates and add a reference of a new scaffold in the scaffolding dialog box.

Any of the answer will be dearly appreciated. Thank you.

like image 428
Md. Alim Ul Karim Avatar asked Apr 13 '15 18:04

Md. Alim Ul Karim


1 Answers

Before continuing to implement your framework using T4, you should be aware that the ASP.Net vNext team have quietly dropped support for T4 from MVC6 projects, so unless that decision is reversed, you will not be able to upgrade your framework.

As of Visual Studio 2015 CTP6, MVC6 projects do not support Single File Generators, which are a requirement for T4. The reasons given by the ASP.Net vNext team are described on the official GitHub repository for ASP.Net.

https://github.com/aspnet/Home/issues/272

UPDATE

David Fowler from the team has now (29-04-2015) confirmed that Single File Generators will be supported in MVC6, which in turn should allow support for T4.

UPDATE 2

To revert back to your original question on the topic of using Custom Code Templates for Scaffolding, this is not finalised for MVC6 and Visual Studio 2015.

I raised this question on the ASP.Net GitHub issue tracker thread mentioned above; Sayed Ibrahim Hashimi (MSFT) replied there will be some discussion regarding which technology and implementation will be followed, and at the moment the main candidates are T4 or Razor generator.

Sayed pointed to the following article that shows some early thoughts, but stresses that this is not finalised, and people should not time invest in this approach as it is likely to change.

http://blogs.msdn.com/b/webdev/archive/2014/08/23/how-to-customize-scaffolding-templates-for-asp-net-vnext.aspx

like image 59
dmcquiggin Avatar answered Oct 04 '22 10:10

dmcquiggin