且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何创建ASP.NET MVC5定制脚手架模板?

更新时间:2023-02-24 22:28:06

首先,它看起来像你有Visual Studio 2013和2012都安装在您的计算机上。我试着找了你提供的路径,我找不到它。在你的路径看起来像你尝试使用MVC4模板。这是我的路径:

First, it looks like you have Visual Studio 2013 and 2012 both installed on your computer. I tried looking up the path you provided, I couldn't find it. On your path it looks like you're try to use MVC4 templates. Here is my path:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\
Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates

下面是我如何定制我的脚手架模板的BaseController:

Below is how I customized my scaffold template for the BaseController:

1)直接在项目文件夹中创建文件夹叫codeTemplate。

1)Create folder call "CodeTemplate" directly in the project folder.

2)进入下面的路径,找到MvcControllerWithActions文件夹全部复制到文件夹codeTemplates

2)Go to below path, find MvcControllerWithActions folder copy all to folder "CodeTemplates"

   C:\Program Files (x86)\Microsoft Visual Studio 12.0\
    Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates

3)进入codeTemplates - > MvcControllerWithActions在您的项目

3)Go to CodeTemplates -> MvcControllerWithActions in your project.

4)有两个文件,​​ Controller.cs.t4 Controller.vb.t4 在MvcControllerWithActions,如果你使用的是C#,删除 Controller.vb.t4

4)There are two files, Controller.cs.t4 and Controller.vb.t4 in MvcControllerWithActions, if you used C#, delete Controller.vb.t4.

5)打开 Controller.cs.t4 文件,修改控制器名称BaseController,如下图所示:

5)Open the Controller.cs.t4 file, modify the Controller name to BaseController, like below:

 public class <#= ControllerName #> : BaseController
    {
    }

6)现在,当您尝试使用创建MVC5控制器添加新的脚手架项目,它会使用模板,你自定义的。

6) Now, when you try to create MVC5 Controller using "add new scaffold item", it'll use the template you customized.

希望它帮助。