• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 54
  • Last Modified:

How can I override the default scaffolding templates in .NET MVC5?

In MVC4, the templates Visual Studio used to scaffold views (List, Create, Edit, Delete, Details) were found in a directory and could be altered, named List.tt.t4. However in MVC5, that no longer seems to be the case. I've altered every occurrence of these templates I could find on C:, including the .cshtml files, but none of them seem to control the code that gets generated.

Every time i generate a view, I have to go through them individually and fix 20 things that Microsoft decided to put in all views, it gets really time consuming.

I'd like to do it globally for all projects, but i'll settle for overriding them on a project by project basis.

Thanks!
0
Myles Cardiff
Asked:
Myles Cardiff
  • 3
  • 2
1 Solution
 
Fernando SotoRetiredCommented:
Hi Myles;

See if the information found on the following two web pages give you the information you are looking for.
ASP.NET Scaffolding in Visual Studio
Creating a Custom Scaffolder for Visual Studio
0
 
Myles CardiffDeveloperAuthor Commented:
Thanks Fernando, but those both only apply to Visual Studio 2013, and are many years old. They've changed everything since these were written.
0
 
Myles CardiffDeveloperAuthor Commented:
For anyone else having this problem, the default scaffolding templates for Visual Studio 2017 are located in:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates\MvcView

Both CS and VB versions are in the same folder. They are protected files, so if you try to edit them directly, you'll get an error. So copy them to another folder, edit them, then copy them back. It will ask you to authorize, and you can overwrite them. Then when you generate a Controller or just a single view, it will have your changes built in :)
1
 
Fernando SotoRetiredCommented:
It applies to MVC 5 VS 2013 and above.
0
 
Myles CardiffDeveloperAuthor Commented:
I figured this out on my own digging through every file, but still wanted others to know this was the fix.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now