Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom scaffold templates in ASP.NET Core

Tags:

Now that I figured out how to enable scaffolding in ASP.NET Core MVC (see View scaffold templates in ASP.NET Core), I'd like to create custom template files for Views. I found one place that said the template files are located here:

C:\Users\{user name}\.dnx\packages\Microsoft.Extensions.CodeGenerators.Mvc\1.0.0-rc1-final\Templates\ViewGenerator

But I copied an existing file there and that copied file does not appear in the Template dropdown on the Add View dialog. Are they located elsewhere, or do I have to do something to get files added in that folder to appear? Restarting Visual Studio did not do that.

like image 384
Rono Avatar asked Jul 14 '16 19:07

Rono


People also ask

How do you create scaffolding in .NET core?

From Solution Explorer, right-click on the project > Add > New Scaffolded Item. From the left pane of the Add Scaffold dialog, select Identity > Add. In the Add Identity dialog, select the options you want. Select your existing layout page so your layout file isn't overwritten with incorrect markup.

What is scaffolding templates in asp net?

Scaffold templates are used to generate code for basic CRUD operations within your ASP.NET MVC applications against your database with the help Entity Framework. These templates use the Visual Studio T4 templating system to generate views for basic CRUD operations with the help of Entity Framework.

How do you customize scaffolds in a Model View Controller or MVC 5 application?

To add a scaffold, right-click on Controllers folder in the Solution Explorer and select Add → New Scaffolded Item. It will display the Add Scaffold dialog. Select MVC 5 Controller with views, using Entity Framework in the middle pane and click 'Add' button, which will display the Add Controller dialog.


2 Answers

I am using Microsoft.VisualStudio.Web.CodeGeneration.Tools 1.0.0-preview2-final

Templates are located here...

C:\Users\{username}\.nuget\packages\Microsoft.VisualStudio.Web.CodeGenerators.Mvc\1.0.0-preview2-final\Templates

Copy the Templates folder to your project and edit them as required.

enter image description here

like image 180
user3012633 Avatar answered Sep 27 '22 19:09

user3012633


I´m using Visual Studio 2017 and asp.net Core 2.0, and after search a lot, I´ve just found the Templates on this place: C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.visualstudio.web.codegenerators.mvc\2.0.0\Templates

I hope this could help someone with the same issue... ;)

like image 23
Fabio Dalonso Avatar answered Sep 27 '22 21:09

Fabio Dalonso