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 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.

Myles CardiffDeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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.
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 :)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
It applies to MVC 5 VS 2013 and above.
Myles CardiffDeveloperAuthor Commented:
I figured this out on my own digging through every file, but still wanted others to know this was the fix.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.