.NET Core 3.1的自定义脚手架模板位置

问题描述

我想为.NET Core 3.1自定义脚手架模板。我找不到ASP.NET Core 3.1脚手架模板的位置。我进行了大量搜索,但所有搜索最终都针对.NET Core 2.1。

其他位置对我不起作用

C:\Program Files (x86)\Microsoft Visual Studio\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates 
C:\Program Files (x86)\Microsoft Visual Studio\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates
C:\Users\<user>\.nuget\packages\microsoft.visualstudio.web.codegenerators.mvc\3.1.4\Templates

我在上述位置更改了模板,但是每次创建新项目时它们都不会反映出来。

解决方法

如果要在项目中自定义脚手架模板,则可以执行以下操作:

首先,将Templates文件夹复制到您的项目中: enter image description here

然后在文件夹中更改Tempaltes,并在项目中创建脚手架项目,它将起作用。(在.net core中,向其添加新模板,它将不起作用,您只能通过方式)

这是一个演示:

我在Templates / ViewGenerator中更改了Create.cshtml(这是一个.net核心mvc项目,因此我删除了Identity,Identity_Versioned,RazorPageGenerator,RazorPageGenerator_Versioned文件夹):

enter image description here

我改变

enter image description here

enter image description here

结果: enter image description here

,

您可以看到

enter image description here

例如:

C:\Users\MyName\.nuget\packages\microsoft.visualstudio.web.codegenerators.mvc

如果您需要一种可编程的方式:https://devblogs.microsoft.com/aspnet/creating-a-custom-scaffolder-for-visual-studio/