t4-editor使用方法 Visual T4
原文发布时间为:2011-05-17 —— 来源于本人的百度文章 [由搬家工具导入]
http://visualstudiogallery.msdn.microsoft.com/40a887aa-f3be-40ec-a85d-37044b239591
可以这里下载,也可以在 vs的 工具——扩展管理器 里面搜索 安装即可。
引入一些常用的命名空间并使用的方法如下:
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension=".txt" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Xml.Linq" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Xml.Linq" #>
<#
var a = "sdfsdf".Select(it => it);
foreach (var b in a)
{
#>
<#= b #>
<#
}
#>
载入自定义dll,如
<#@ Assembly Name="E:\CodeTest\TestT4\My\bin\Debug\My.dll" #>
<#@ Import Namespace="My" #>
一个模板生成多个文件,范例(详见:http://www.olegsych.com/2008/03/how-to-generate-multiple-outputs-from-single-t4-template/)
<#@ template debug="False" hostspecific="True" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Xml.Linq" #>
<#@ assembly name="System.Web" #>
<#@ Assembly Name="System.Web.Mvc" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Xml.Linq" #>
<#
HelloWorld(12);
SaveOutput("test1.txt");
HelloWorld(13);
SaveOutput("test2.txt");
HelloWorld(14);
SaveOutput("test3.txt");
#>
<#+
void HelloWorld(int i)
{
Write("Hello World" + i);
#>
This is file <#= i #>
<#+
}
#>
<#+
void SaveOutput(string outputFileName)
{
string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);
string outputFilePath = Path.Combine(templateDirectory, outputFileName);
File.WriteAllText(outputFilePath, this.GenerationEnvironment.ToString());
this.GenerationEnvironment.Remove(0, this.GenerationEnvironment.Length);
}
#>
http://www.olegsych.com/2008/03/how-to-generate-multiple-outputs-from-single-t4-template/
中文MSDN这里:http://msdn.microsoft.com/zh-cn/library/dd820620
Tutorials:Creating your first code generatorTroubleshooting code generation errorsDebugging code generation filesCreating reusable code generation templatesCreating complex code generatorsReusing code generators on multiple projects
Here's some of the links from Oleg's blog.
How to create a simple T4 templateHow to use T4 to generate .config filesHow to use T4 to generate Decorator classesHow to use T4 to generate CRUD stored proceduresHow to use T4 to generate strongly-typed navigation class in ASP.NET (by Kirill Chilingarashvili) How to use T4 to generate strongly-typed AzMan wrapperHow to generate multiple outputs from single T4 templateT4 template for generating ADO.NET Entity Framework Stored Procedures (by David DeWinter) T4 script for generating ADO.NET Entity Framework Views (by ADO.NET team) T4 template for generating LINQ to SQL Data Context (by Damien Guard) T4 template for generating WiX source files (by New Age Solutions) T4 template for generating SQL view from C# enumerationMSBuild task for transforming T4 templates (by Elton Stoneman) T4 template for generating state machines in C# (by Andrew Matthews)
Oleg also has a CodePlex project called T4 Toolbox that is a library of T4 templates that get added to File | New Item.
Also, check out Damien Guard's T4 templates that are a wholesale replacement of code that LINQ to SQL generates.
===其他的学习,可以到这个hanselman的博客。
t4-editor使用方法 Visual T4的更多相关文章
- tangible T4 Editor 2.2.3 for VS2010 / VS2012 / VS2013 Preview
tangible T4 Editor 2.2.3 for VS2010 / VS2012 / VS2013 Preview angible T4 Editor 2.2.3 plus UML model ...
- tangible T4 Editor 2.2.3 plus modeling tools for VS 2012 扩展名
tangible T4 Editor 2.2.3 plus modeling tools for VS 2012 扩展名 tangible T4 Editor 2.2.3 plus modeling ...
- Cannot+use+T4+templates+inside+a+.NET+Core+project,NetCore2.0无法使用T4模板解决方法
Cannot+use+T4+templates+inside+a+.NET+Core+project,NetCore2.0无法使用T4模板解决方法 请见:https://csharp.wekeepco ...
- ef code first transform,add ef power tools add-in,add tangible t4 editor for enhancement.
use ef power tools, as to .edmx file,right click at view, choose generate database from model, then ...
- 查看html元素绑定的事件与方法 visual Event 插件
WEB标准提倡结构.表现和行为相 分离,现在越来越多采用这种表现和行为的方式,但它也为我们开发调试带来一些问题,网页载入一堆JavaScript,,我们很难搞清楚最后在哪些元素的哪个动作绑定了事件,尤 ...
- easyui datagrid 动态操作editor 的方法
easyui本身是不提供这么细节的功能的,需要我们自己拓展下: 在easyui.min.js中扩展: $.extend($.fn.datagrid.methods, { addEditor : fun ...
- Visual Studio 2013中引入Web Service的简单方法visual studio 引用 wsdl
http://blog.csdn.net/wangzhongbo_24/article/details/49954191 Web Service有三种表示方式 三种方式分别为WSDL.Endpoint ...
- 编写C语言的两种方法----Visual Studio/CodeBlocks
1.CodeBlock(安装简单) 参考这个博客的:https://blog.csdn.net/jjjjkkjkk/article/details/80331625?utm_medium=distri ...
- T4模板
T4,即4个T开头的英文字母组合:Text Template Transformation Toolkit. T4文本模板,即一种自定义规则的代码生成器.根据业务模型可生成任何形式的文本文件或供程序调 ...
随机推荐
- 快速搭建lvs + keepalived + nginx
环境: VIP 192.168.2.224 LVS 192.168.2.217 centos7 nginx1 192.168.2.231 c ...
- 5.Cisco Packet Tracer里关于交换机或路由器配置文件和系统映像备份与恢复
我们会将交换机或路由器的配置文件和系统镜像直接备份到tftp服务器上,所以我们需要准备一台tftp的服务器 1我们需要给服务器配一个ip地址,给路由器的f0/1端口配置一个ip地址,路由器与服务器能相 ...
- JS进阶篇--JS数组reduce()方法详解及高级技巧
基本概念 reduce() 方法接收一个函数作为累加器(accumulator),数组中的每个值(从左到右)开始缩减,最终为一个值. reduce 为数组中的每一个元素依次执行回调函数,不包括数组中被 ...
- 【CSS】非常简单的css实现div悬浮页面底部
<div id="demo_div"></div> <style> #demo_div{ left:; position: fixed; bot ...
- PHP递归排序怎么实现的?
递归算法对于任何一个编程人员来说,应该都不陌生.因为递归这个概念,无论是在PHP语言还是Java等其他编程语言中,都是大多数算法的灵魂. 对于PHP新手来说,递归算法的实现原理可能不容易理解.但是 ...
- 科学计算库Numpy——运算
np.multiply(array1,array2) 该函数用于数组中对应位置上的数相乘. 一维向量 二维数组 np.dot(array1,array2) 两个数组都是一维向量 数组中对应位置上的数相 ...
- 04vim的使用
linux常用命令 workon 查看已经安装的虚拟环境 deactivate 退出虚拟环境 whoami 查看用户 sudo bash install.sh 添加权限 pwd 查看在那个路径下 cd ...
- while循环中continue和break的区别
除了满足while条件外,还有两种方法可以终止循环,它们分别是break和continue.它们唯一的区别是break跳出整个循环,直接执行下面的代码了;而continue是终止当次循环,不执行下面的 ...
- python语言介绍
Python诞生于1989年,作者是吉多.范罗苏姆,人称龟叔,由C语言实现的. 1999年,基于python的web框架Zope 1诞生,标志着python向web领域迈出了第一步,现在这个框架好像不 ...
- 678. Valid Parenthesis String
https://leetcode.com/problems/valid-parenthesis-string/description/ 这个题的难点在增加了*,*可能是(也可能是).是(的前提是:右边 ...