Custom scaffold templates in ASP.NET Core

2020-01-29 04:13发布

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.

4条回答
霸刀☆藐视天下
2楼-- · 2020-01-29 04:25

Latest version as of Oct 2018 could be found in GitHub of the Asp.NET https://github.com/aspnet/Scaffolding/tree/master/src/VS.Web.CG.Mvc/Templates

查看更多
该账号已被封号
3楼-- · 2020-01-29 04:29

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

查看更多
叛逆
4楼-- · 2020-01-29 04:30

You can enable code generation rather than copying from templates folder.

Using the tutorial Asp.Net Core Using existing db

Tools > Nuget Package Manager > Packagae Manager Console

Run the following commands one after the other. Make sure you have internet connection.

Install-Package Microsoft.EntityFrameworkCore.SqlServer
Install-Package Microsoft.EntityFrameworkCore.Tools
Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design

Rebuild the solution. Then right click on the controller folder > new > controller...

查看更多
▲ chillily
5楼-- · 2020-01-29 04:38

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

查看更多
登录 后发表回答