ASP.NET MVC 5 Custom Scaffolding Option [t4 templates] - asp.net-mvc

Currently , I am developing a framework , I want to add custom scaffolding option in visual studio menu.
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"
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.

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

Related

how to add asp.net mvc templates for monodevelop

I'm on archlinux using mono 4.0.4 and monodevelop 5.9.
By following the Getting started guide I noticed there are some scaffolding options missing, I see some nuget packages for scaffolding but installing them didn't do much.
SO has these two questions :
How to get the MVC 3 or 4 template in MonoDevelop?
Developing ASP.NET MVC using MonoDevelop on MAC
The latter is for Mac and both of them are outdated As I'm talking about asp.net mvc 5 here.
searching didn't reveal anything apart from the Nuget packages I added and I can't see any addins in the add-in manager for this(prefer not to use beta or alpha addins).
So what to do to get these ?
P.S:
I know I can get them with yoeman but I like to use monodevelop, if yoeman can be integrated with monodevelop So I can see options like "model with view and controller" scaffolding(that is a CRUD ready application) then I'll do it.
I am assuming you are talking about the templates that are available in an ASP.NET MVC application when you select Add View or Add Controller. If this is not the case then please update your question with more information.
The templates listed when adding a new view or controller to an ASP.NET MVC project are taken from t4 template files (.tt) in the following folders:
AddIns\AspNet\CodeTemplates\CSharp\AddController
AddIns\AspNet\CodeTemplates\CSharp\AddView\Razor
You can add extra .tt files into this folder and they will be displayed in the Add View and Add Controller dialog.
Out of the box MonoDevelop/Xamarin Studio only has a few t4 templates available so you would need to either write your own or find some from elsewhere. SharpDevelop has more T4 templates or MVC which could probably be used but may require some modification.

Mixing MVC and Webforms - Displaying BOTH Context Menus

I have added MVC4 to an ASP.NET Webforms project in Visual Studio 2010.
I changed the .csproj's project type to that of an MVC4 project as detailed here:
Context menu to Add Controller/View missing
to give me the MVC specific context menus.
Now the ASP.NET Webforms context menus (such as add 'UserControl') are gone.
How can I hack VS2010 to give me both the MVC4 and ASP.NET context menus for a given project?
In short and officially: no, this is not possible (disclaimer: I'm a software engineer at Microsoft who used to work on Visual Studio + Blend, but now Internet Explorer).
In Visual Studio, a project only has a single type, and the "ASP.NET Web Application" (WebForms) and "ASP.NET MVC Application" (ASP.NET MVC) are two different project types - they're very similar and share common features, but are still different types.
The MVC project type does not have UserControls and other Items in the Add New Item dialog or context-menus because they're largely irrelevant and wouldn't work as you expect them to (granted, it is possible to have WebForms (and not just using .aspx files as Views)) but I don't think it's a good application-design decision.
Unofficially... the items that appear in the Add New Item dialog are specified in the registry. This is documented here: https://msdn.microsoft.com/en-us/library/bb165141.aspx however this information is intended for developers of new project types, rather than allowing users to modify their own (and certainly you're at risk of breaking your VS if we release another update which makes assumptions about how your Add New Item templates are configured).
If you want to do it this way - go ahead, but be careful, and make a note of everything you do so you can undo it.
Since the IDE is based on working in single mode, It seems we have 2 ways:
Attempt to use a configuration that is done an OR action between two project types, so we have both of them, but lack of true functionality is demanded :(
Write some lines of C++ code to change configuration immediately (based on tip here), so you have a switcher application to run when you want :)

No ASP.NET MVC 5 Web Application Template on VS 2012?

I'm using Visual Studio 2012 and have just installed "Microsoft ASP.NET and Web Frameworks 2013.1 - Visual Studio".
As expected, it added the option to create an "ASP.NET MVC 5 Empty Project". The thing is, I see no way of jump-starting an already functional "base application" as I had when I was using MVC 4 (e.g. "Asp.NET MVC 4 Web Application"). I only see an empty template.
I've seen answers such as:
How can I add the MVC 5 project template to VS 2012?
Create and Run MVC 5 Project in VS 2012
Direct download link to ASP.NET MVC 5 for VS 2012
And found this article on the matter.
This is obviously not a show-stopper as I can always create the application from a scratch, but I still would like to know if it is possible to achieve that on VS 2012. Did I miss a step, or do I need VS 2013 for that? A fully functional Web application template (with authentication etc.) would be nice to dabble around MVC 5's new features or for prototyping.
After creating a new project using ASP.NET MVC 5 Empty Project, you can right click on the project, then click Add.. > New Scaffolded Item..., select MVC on the left, then MVC 5 Dependencies and choose Full dependencies from the prompt.
This will add a default layout (Views\Shared\_Layout.cshtml), Content folder, Scripts folder with bootstrap, jquery, modernizr, etc, and other things the Web Application template creates.
If you get the error "CS0103: The name 'Styles' does not exist in the current context" just add <add namespace="System.Web.Optimization"/> under <namespaces> in Views/web.config
The answer from Sean Lynch is nice but not really complete.
However there is this nice guy that took the time to prepare the template just like in Visual Studio 2013. You will get everything down to the bootstrap template and pre-configured database table for authentication.
All you need to do is change the DefaultConnection in Web.Config to you SQL Server and voila all the relevant authentication table will be created for you.
Archive of the original blog (by web.archive.org)
Update
The original blog is no longer online, but thankfully his template is still online. You can download the MVC5 Template for Visual Studio 2012 Here:
Direct link to MVC5 Template For Visual Studio 2012
And here is the excerpt from the original blog:
Installing the template is very simple, there are just two steps:
Copy it into the following folder of your computer (creating the directory structure if necessary):
%USERPROFILE%\Documents\Visual Studio 2012\Templates\ProjectTemplates\Visual C#\Web
Once you’ve done this, simply restart Visual Studio and you will have this template available in the dialog box to create a new project under “Visual C# > Web”.
Now you can create applications with a little more shape than the mere empty structure provided by default and enjoy the benefits of adopting Bootstrap and its responsive design, a full membership system and user authentication, bundles, filters, some content pages, etc.
You have 2 option to fix it.
Install the latest 2013 version which have MVC5 support inbuilt (VS2013 missing MVC3 and ASPX file template (ASPX templates will be added in future))
stay with 2012 update 4. Read my old article to get it fixed http://geekswithblogs.net/anirugu/archive/2013/11/28/mvc-5-in-visual-studio-2012-update-4.-how-to.aspx
I'm not using 2012 now, but rather 2013, and I see the mvc 5 template there. However, I did this a while back before I had any mvc 5 templates showing up by installing mvc 5 first. You should be able to download from http://www.asp.net/mvc/mvc5.
Also make sure your target framework is set correctly.
Then I updated the web config like this:
You have to have the correct versions of the assemblies. I googled a lot to get this info, so it should still be available if you do some research.

How to write an MVC3 Project Template that will offer option Razor or .aspx views

I have written two separate project templates to create MVC3 projects (both based on the standard Microsoft template, but with additional controllers/views of my own) - one with ASPX views, and the other with Razor views.
But, rather than have two separate templates, I would rather mimic the way that the Microsoft MVC3 template works, which offers both view engine options, selected in a second dialog. I know that this is done with a Wizard, but I can't find the Wizard in the MVC source code (which I've downloaded). Does anybody know where to find the Wizard, or have other helpful suggestions? Thanks.
The custom MVC New Project dialog exists in Microsoft.VisualStudio.Web.Mvc.3.0.dll. We do not ship the source code for that assembly.
I used the Export Template Wizard to create an ASP.NET MVC3 Project Template of my own. This worked OK, but did not offer the same options that Microsoft ships with their Visual Studio MVC assembly. I also ran into an issue where the strongly-typed views were not being updated with the correct namespace. They were keeping the namespace of my original project, while the Controllers and Model was correct.
We would love to have the source code made available for MVC 3 Project Templates!
Here is the Wizard I used. It definitely comes in handy. http://visualstudiogallery.msdn.microsoft.com/57320b20-34a2-42e4-b97e-e615c71aca24/
Phil Haack has documented how to create a custom MVC3 project template that will appear inside that wizard (as opposed to a normal project template that won't)
haacked.com/archive/2011/06/06/creating-a-custom-asp-net-mvc-project-template.aspx
If you follow that process you'll only end up with razor as the possible view engine. To get other view engines, you need to expand the reg files to list spark etc. Details on doing that are provided in this stack overflow answer:
Add custom viewengine to New project dialog?

Tools for auto-generating ASP.NET MVC CRUD UI?

Does anyone know of any tools for generating ASP.NET MVC CRUD User Interfaces (E.g. the controllers and views for Admin tools), given:
A set of model objects.
A set of repositories for retrieving those objects.
Thanks
There is a project on codeplex called MVCCrud this will automate repository and controller. Also optionally supports JqGrid (searching, sorting etc). It isnt included in the project but its very simple to add some T4 templates to generate the desired view.
If you just want normal crud functionality this is very very quick. Only downside is the only repository is Linq2Sql, but you can easily add your own using their interface it is prity simple to extend or use parts of.
The Crud Template which are shipped with ASP.NET MVC are based on T4 which is a code generation tool which ships with Visual Studio. This means you can take the templates and customize them based on your taste and make your own...
take a look at Scott Hanselman's ninja tips and tricks video's he goes into details here:
http://channel9.msdn.com/posts/matthijs/ASPNET-MVC-2-Ninja-Black-Belt-Tips-by-Scott-Hanselman/
Serenity Platform
Serenity is an open source project aiming to reduce boiler-plate code in your development project.
It comes with a T4 based code generator that will produce services and UI for your tables.

Resources