Customizing ASP.NET MVC 5/Web API 2 Scaffolding Templates in Visual Studio 2013

        Introduction:


                    Scaffolding in ASP.NET allows you to automatically generate code in web application. This make it easy to quickly add boilerplate code in your application. There is a nice introduction of scaffolding in ASP.NET application using Visual Studio 2013 at here. The default templates are good for a lot of cases, but sometimes you want to customize these scaffolding templates for all your applications and sometimes you need to use different scaffolding templates in different projects. In this article, I will show you how to customize the default scaffolding t4 templates in ASP.NET MVC 5 and ASP.NET Web API 2 globally and per project.


        Description:

 

 

                    If you need to customize the scaffold templates globally then just navigate to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates (depending upon where Visual studio reside),

 

                     

                   


                    In the above explorer, you can globally update the t4 templates of ASP.NET MVC 5 and ASP.NET Web API 2.

 

                    Now for per project base, just create a CodeTemplates folder in your application root and paste the above folders inside CodeTemplates folder,

 

                     

 

                    You can read more about this at here.

 


        Summary:


                    In this article, I showed you how you can easily customize the default code generation(scaffolding) templates in ASP.NET MVC 5 and ASP.NET Web API 2 using Visual Studio 2013. Hopefully you will enjoy my this article too.



Published Sunday, September 15, 2013 1:00 PM by imran_ku07

Comments

# re: Customizing ASP.NET MVC 5/Web API 2 Scaffolding Templates in Visual Studio 2013

Tuesday, October 29, 2013 1:13 PM by Andrew Brown

Ibrahim, thanks for this information.  Previously with MVC Scaffolding in VS 2010 and 2012 we were able to override the Powershell scaffolding scripts as well as class files and views.  Is there a way to do this with the build in VS 2013 scaffolding?  The only information I can find on the internet is how to override the class files and views.  

My need is that I want to scaffold the old CreateOrEdit.cshtml and a new DetailsOrDelete.chtml partial views.