原文发布时间为: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的博客。

http://www.hanselman.com/blog/T4TextTemplateTransformationToolkitCodeGenerationBestKeptVisualStudioSecret.aspx

t4-editor使用方法 Visual T4的更多相关文章

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

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

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

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

  5. 查看html元素绑定的事件与方法 visual Event 插件

    WEB标准提倡结构.表现和行为相 分离,现在越来越多采用这种表现和行为的方式,但它也为我们开发调试带来一些问题,网页载入一堆JavaScript,,我们很难搞清楚最后在哪些元素的哪个动作绑定了事件,尤 ...

  6. easyui datagrid 动态操作editor 的方法

    easyui本身是不提供这么细节的功能的,需要我们自己拓展下: 在easyui.min.js中扩展: $.extend($.fn.datagrid.methods, { addEditor : fun ...

  7. Visual Studio 2013中引入Web Service的简单方法visual studio 引用 wsdl

    http://blog.csdn.net/wangzhongbo_24/article/details/49954191 Web Service有三种表示方式 三种方式分别为WSDL.Endpoint ...

  8. 编写C语言的两种方法----Visual Studio/CodeBlocks

    1.CodeBlock(安装简单) 参考这个博客的:https://blog.csdn.net/jjjjkkjkk/article/details/80331625?utm_medium=distri ...

  9. T4模板

    T4,即4个T开头的英文字母组合:Text Template Transformation Toolkit. T4文本模板,即一种自定义规则的代码生成器.根据业务模型可生成任何形式的文本文件或供程序调 ...

随机推荐

  1. session 关于localhost和本地IP地址 不共享问题

    打比方,  一个请求 localhost:8080/test/test  ,一个本地Ip(172.1.1.1:8080/test/test) 1.请求localhost方式 HttpSession s ...

  2. nginx 如何配置来获取用户真实IP

  3. DDOS与DOS的区别

    0x01 在说之前,先看一些例子吧 还有众所周知的中美黑客大战,新闻我就不说了 0x02 什么是DOS DoS是Denial of Service的简称,即拒绝服务,造成DoS的攻击行为被称为DoS攻 ...

  4. 【CodeBase】PHP检查未知媒体文件的格式

    用法: <?php $filefullpath="F:/test/2awd45wr1e5fef5e5"; echo Format::check($filefullpath,[ ...

  5. nova boot添加volume_type参数支持

    早前由于添加了全SSD的高性能Ceph集群,区别于现有的HDD集群,在OpenStack端需要能够选择使用两种集群.Cinder配置多Ceph后端的文档早已整理,整理文件夹时发现这篇为nova boo ...

  6. IntentService和Service执行子线程对比

    1.为何要用子程序 服务是在主线程中执行的,直接在服务中执行耗时操作明显不可取,于是安卓官方增加了IntentService类来方便使用 在Service中执行子程序代码如下 @Override pu ...

  7. 15,scrapy中selenium的应用

    引入 在通过scrapy框架进行某些网站数据爬取的时候,往往会碰到页面动态数据加载的情况发生如果直接用scrapy对其url发请求,是获取不到那部分动态加载出来的数据值,但是通过观察会发现,通过浏览器 ...

  8. Android 自定义debug.keystore

    场景分析: 有时候,我们要使用第三方的服务,需要提供自己的包名以及keystore的sha1值,比如微信支付,百度地图,都需要包名和keystore的sha1值作为唯一标识.这时候我们测试的时候,如果 ...

  9. logback mybatis 打印sql语句

    logbac.xml 文件的基础配置参考的园友的 http://www.cnblogs.com/yuanermen/archive/2012/02/13/2349609.html 然后hibernat ...

  10. 使用 Spirit 类在 XNA 中创建游戏中的基本单位精灵(十三)

    平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...