Is there a way to add a new Scaffold or override the Scaffolding functionality used in the new Visual Studio 2013 Scaffolding?
The only documentation I can find on the internet is how to override the T4 templates using the CodeTemplates folder. I want to add a new Scaffold to the list when Add... > New Scaffold Item... It looks like in Visual Studio 2013 this has been rolled into a library (Microsoft.AspNet.Scaffolding.Mvc.5.0.dll) and registered in the GAC or as a VS Extension.
I want to override the mechanism that calls the T4 templates so I can create different files and enhanced the functionality. My specific need is that I want to scaffold the old CreateOrEdit.cshtml and a new DetailsOrDelete.chtml partial views. I would also like to Scaffold a tool that takes a resource file and generates the localized resource file in another language.
In Visual Studio 2013 RTM there is no support for adding completely custom scaffolders. You can only do the following customizations:
- You can edit or override the existing T4 templates for controllers, areas, views, etc.
- You can add custom view scaffolders that will show up in the existing MVC View scaffolder
The Visual Studio team is working on re-enabling custom scaffolder support in a future update of Visual Studio.
To add a custom view scaffolder today:
- Create any ASP.NET project in VS2013
- Add a folder called
CodeTemplates
- Create a sub-folder in there called either
MvcView
orMvcViewWithoutModel
depending on whether your custom view template is a strongly-typed view - Create a file there in the form of
<templatename>.<lang>.t4
where the<templatename>
is whatever you want to show up in the MVC View scaffolder's drop down list and<lang>
is eithercs
orvb
.
To get started you can copy any existing scaffolder from VS2013's default list and customize it. You can get the built-in scaffolders from here:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates\MvcView
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates\MvcViewWithoutModel
If you use the same name as an existing scaffolder then it will override the built-in scaffolder, even when called from another scaffolder. For example, the MVC controller scaffolder will use an overridden view scaffolder that is in your project.
4/22/2014 Update
Now that previews of Visual Studio 2013 Update 2 are available, it is possible to write completely custom scaffolders.
Check out this blog post that walks through how to write a custom scaffolder: Creating a Custom Scaffolder for Visual Studio
来源:https://stackoverflow.com/questions/19665197/how-to-add-new-scaffold-used-in-visual-studio-2013-scaffolding