13
votes

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.

1
Create , delete, details .. etc are views NOT controllers. The t4 templates are hit when you "add View" from the controller. You then select Template to select the new scaffold itemuser1752532
With due respect, what you are saying implies when we generate single views , however I am focusing on the full read/write as mention in the description. Single view generation we can control but how about the fully context generation.Md. Alim Ul Karim
With due respect , the wording for your question is completely wrong. You want to create controller templates , not view templatesuser1752532
have you seen this link? Looks like you can add your own options to that list by following this post. It's referenced from the official Microsoft documentation hereFrank
Thank you @Frank. You just saved the day.Md. Alim Ul Karim

1 Answers

8
votes

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