如何创建ASP.NET MVC5定制脚手架模板? [英] How to create custom scaffold templates in ASP.NET MVC5?

查看:163
本文介绍了如何创建ASP.NET MVC5定制脚手架模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET MVC5和VS2013

I'm using ASP.NET MVC5 and VS2013

我试图复制codeTemplates文件夹从

I've tried to copy CodeTemplates folder from

C:\ Program Files文件(x86)的\微软的Visual Studio 12.0 \ Common7 \ IDE \ VWDEx preSS \的ItemTemplate \ CSHARP \网络\ MVC 4 \ codeTemplates

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\VWDExpress\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates

与子文件夹AddController,AddView,并在他们里面T4模板,然后我修改了一些模板,但是当我试图添加视图控制器也什么都没有发生。

with subfolders "AddController", "AddView" and T4 templates inside them, then I modified some templates, but nothing happened when I tried to add View nor Controller..

推荐答案

首先,它看起来像你有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.

希望它帮助。

这篇关于如何创建ASP.NET MVC5定制脚手架模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆