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

1

13

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.

Falkner answered 13/4, 2015 at 18:38 Comment(7)
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 itemMetheglin
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.Falkner
With due respect , the wording for your question is completely wrong. You want to create controller templates , not view templatesMetheglin
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 hereRemanence
Thank you @Frank. You just saved the day.Falkner
@qwfddq glad to help but if that does not work out you might want to check out my extension for working with T4 templates (T4 Awesome). Depending on your needs it might work out better as it allows you to quickly create and share your own custom T4 scaffolding frameworks. The full version cost money but I offer a community version you can use for free forever.Remanence
Of course @Frank. You can post it as the answer and I will select it. Thank you man.Falkner
W
8

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

Wastage answered 27/4, 2015 at 14:31 Comment(6)
I can only say I wish it were otherwise - please do read the discussion I linked to, as it is technically possible to have T4 support in MVC6. It seems that the team, for some reason, thought it was unimportant. I raised it with Scott Hanselmann, who says he will look into this after the Build conference, and the ASP.Net vNext team say 'watch this space'. If they do not think people want to use T4 with MVC6, then they will not bother, so I would suggest making your opinion known to the team.Wastage
I will definitely. Thank you again.Falkner
UPDATE David Fowler from the team has now confirmed that Single File Generators will be supported in MVC6, which in turn should allow support for T4.Wastage
That's great @McQuiggdFalkner
UPDATE 2 The future implementation of Code Template functionality for MVC6 has not been finalised. If there is any progress on this issue, I will clean up the posted answer with relevant information and links. The situation is still fluid.Wastage
Can you, please, add some update now (After 3 years and ASP.NET core)?Mendive

© 2022 - 2024 — McMap. All rights reserved.