Search code examples
asp.net-mvcvisual-studioscaffoldingasp.net-mvc-scaffolding

Change CRUD Scaffolder (Scaffolding) in Visual Studio 2019


I am using Visual Studio 2019, with .NET Framework 4.8, creating ASP.NET MVC 5 software (not Core).

I would like to use the CRUD Scaffolder from an older version of Visual Studio (e.g. 2017 or 2015). I have searched on internet and on Microsoft site; I cannot find anything. I do not have the older versions of software now.

In one of the older versions, the CRUD scaffolder created Views with simple code-

@Html.EditorFor(model => model.xxx)
@Html.EditorFor(model => model.yyy)
@Html.EditorFor(model => model.zzz)

along with of course the rest of the view code. And this is what I would like to do in VS 2019 (for just the scaffolded Views). I am looking to simplify the scaffolded view code (as was the case in older versions of VS).

QUESTIONS:

  1. Is there a way to download and install/copy the older scaffolders?

  2. If not the above, is it possible and easy to copy and modify the current VS2018 scaffolder code? Where could I find info on how to do it?


Solution

  • You will need to create custom scaffolding templates for that.

    Here is a great link. https://learn.microsoft.com/en-us/archive/msdn-magazine/2018/march/asp-net-use-razor-to-generate-html-for-templates-in-a-single-page-app

    Scroll down to Changing the Scaffolding.

    This is for VS 2017. The default template path in VS 2019 is C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates\MvcView

    You will also need to put everything in CodeTemplates\MvcView if you will be creating your own T4 template.

    You will just have to install the older versions of VS to get their T4 Files.

    Here is another great tutorial on how to do this. Hopefully some of this helps.