博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何创建自定义ASP.NET MVC5脚手架模板?
阅读量:7096 次
发布时间:2019-06-28

本文共 2876 字,大约阅读时间需要 9 分钟。

I'm using ASP.NET MVC5 and VS2013

I've tried to copy CodeTemplates folder from

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

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

 

2016年03月31日32分07秒

 

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 trying 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

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

  1. Create folder called "CodeTemplates" directly in the project folder.

  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. Go to CodeTemplates -> MvcControllerWithActions in your project.

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

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

    public class <#= ControllerName #> : BaseController{}
  6. Now, when you try to create MVC5 Controller using "add new scaffold item", it'll use the template you customized.

Hope it helps.

 

2016年03月31日32分07秒

 

The MVC5 T4 templates are located in C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\VWDExpressExtensions\Microsoft\Web\Mvc\Scaffolding\Templates\MvcView

 

2016年03月31日32分07秒

 

MVC4 and MVC5 templates are located in different locations. While MVC4 templates are located in the folder you've given, MVC5 templates are located in this folder:

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

What you need to do for customizing is to create a folder named CodeTemplates your project folder, and copy the templates you want to customize to the CodeTemplates folder.

You'll need to copy MvcView and MvcControllerWithContext folders in order to use with MVC 5 Controller with view, using EntityFramework command.

CAUTION

  • Both directories must have the same folder structure. What I mean is, do not copy the Create.cs.t4in the MvcView folder directly into the CodeTemplates folder. Just copy the entire MvcView folder intoCodeTemplates folder.

  • Do not delete include files such as Imports.include.t4 and ModelMetadataFunctions.cs.include.t4because other files need them to be there.

  • If you're using C#, feel free to delete files with .vb.t4 extension and vice versa.

 

2016年03月31日32分07秒

转载于:https://www.cnblogs.com/zcm123/p/5343813.html

你可能感兴趣的文章
跨域资源共享(CORS)在ASP.NET Web API中是如何实现的?
查看>>
MYSQL建表语法(主键,外键,联合主键)
查看>>
Docker容器的IO基准
查看>>
PostgreSQL 在铁老大订单系统中的schemaless设计和性能压测
查看>>
SaaS模式与ASP模式的差异分析报告
查看>>
[译]函数式响应编程入门指南
查看>>
解决tiny4412串口终端不能输入的问题
查看>>
FCN
查看>>
BloomFilter算法概述
查看>>
关于static 访问权限、继承、多态、内部类结合在一起时的使用方法
查看>>
HIMSS博览会首登中国 建言医卫IT新发展
查看>>
苹果将知名黑客Kristin Paget招致麾下
查看>>
【机器学习PAI实践七】文本分析算法实现新闻自动分类
查看>>
SACC 2013:大数据可视化应用及推荐
查看>>
这里有一份面筋请查收(七)
查看>>
在 Cocos2d-x 中使用 OpenSSL
查看>>
Python 进阶_OOP 面向对象编程_self 的实例绑定
查看>>
JAVA在win10上的安装环境配置
查看>>
闵春榕:PCIE SSD在数据库优化中的应用
查看>>
Easystack陈喜伦:OpenStack市场走强,聚集效应加剧
查看>>