
Probably many have already appreciated the convenience of creating web applications using the scaffolding technology that appeared in ASP.NET MVC 3. Time passed and now Visual Studio 2013 and ASP.NET MVC 5 came out. asynchronous methods and much more.
In this article, I want to talk about how you can enhance the capabilities of this wonderful tool.
As you know, scaffolding in ASP.NET allows you to automatically generate code in web applications. This makes it easier and faster to create working prototypes of applications and saves time, allowing you to focus on core tasks and not spending it on routine operations.

Templates
Before moving on to the actual configuration and expansion of scaffolding capabilities, you first need to understand how it works. All generation of forms and code occurs by applying special templates that define the rules and logic for generating code. ASP.NET MVC uses T4 files as templates.
')
What is T4?
The Text Template Transformation Toolkit, better known as T4, is a set of templates supplied with Visual Studio. Source T4 files are usually stored with an extension. TT Templates T4 is used as a tool to automate the creation of text files with various parameters. These text files can be essentially anything - a markup, a set of styles, a block of code, etc. (XML, HTML, XAML, etc.) T4 uses a special template format, which can contain .NET code and string literals. After preparation, the templates are analyzed with a special utility and compiled into .NET code. As a result of the execution of this code, text files are generated.
T4 templates are used not only in ASP.NET MVC, but also in the ADO.NET Entity Framework and other technologies where automation of the code generation process is necessary.
Customize existing templates.
The templates used in Visual Studio by default are certainly good, but often their capabilities are not enough to implement all the logic, the implementation of which I would like to automate. This article will tell you how you can customize your own templates, as well as about my set of templates that I am willing to share.
Usually, after installing Visual studio 2013, standard templates are located in the directory
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates

If you make changes to one of these templates, it will affect all subsequent projects where you will use automatic form generation. However, there is a way that allows you to set a generation template for each individual web application. To do this, in the project structure, at the root, you need to create a directory CodeTemplates and copy into it the templates that you plan to change.

After that, the form generation tool will use the already changed templates.
X.Scaffolding Templates
Not long ago, I wrote about the X.Scaffolding project, which extends the capabilities of a web application created on the basis of page generation.
Today I want to offer our readers an addition to this project - a set of templates X.Scaffolding.Templates, which is also available through the NuGet repositories. You can install this package, create all necessary forms, and painlessly remove it from the project.
What is the difference of templates from this package?
- Paging support (based on IPageList library)
- Modified templates with tighter integration with Bootstrap
- Authorize (true) attribute for controllers by default
Join now!
Anyone can either get acquainted with the templates, and suggest their own changes.
GithubThe project is available on
GitHub .

NugetYou can install the package from the
NuGet repository:
Install-Package xscaffolding.templates
After creating all the necessary forms, the package can be removed.
Useful information
Based on
Customizing ASP.NET MVC 5 / Web API 2 Scaffolding Templates in Visual Studio 2013