查看 ASP.NET Core 中的脚手架模板

View scaffold templates in ASP.NET Core

MVC 5 在创建视图时具有非常方便的功能,能够select 用于构建视图的模板。这使用 T4 模板文件根据指定类型生成 CSHTML 文件。

在 ASP.Net Core 1.0 中有这样的方法吗?

dependencies 下的 project.json 中添加以下行。

"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": "1.0.0-preview2-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": "1.0.0-preview2-final"

此外,在 tools

下添加以下内容
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": "1.0.0-preview2-final"

保存文件,它应该会恢复包,必要时重新启动 Visual Studio。

现在,当您右键单击时,您应该会在“添加”下看到“新建脚手架项目...”选项

您需要添加对工具的引用。但仅限 构建时间

project.json 中,将以下内容添加到 dependencies 部分:

"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
  "version": "1.0.0-preview2-final",
  "type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc":  {
  "version": "1.0.0-preview2-final",
  "type": "build"
}

仍然在 project.json 中,找到 tools 部分并添加以下内容

"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
  "version": "1.0.0-preview2-final",
  "imports": [
    "portable-net45+win8"
  ]
}

我知道这是旧的,但对我来说,它是通过打开 myProject.sln 解决的,它加载了解决方案,然后控制器等选项可用。