2012-04-17 68 views

回答

4

您可以使用t4Toolbox中的RenderToFile來執行此操作。從文檔示例

片段爲2016年10月12日:

  • 創建帶有兩個C#類庫Visual Studio解決方案突出ClassLibrary1.csproj和ClassLibrary2.csproj。

  • 將一個名爲CodeGenerator.tt的新代碼生成文件添加到第一個類庫項目中。

  • 新文件的修改內容看起來像這樣

<#@ template language="C#" hostspecific="True" debug="True" #> 
<#@ output extension="txt" #> 
<#@ include file="T4Toolbox.tt" #> 
<# 
    SampleTemplate template = new SampleTemplate(); 
    template.Output.File = @"SubFolder\SampleOutput.txt"; 
    template.Output.Project = @"..\ClassLibrary2\ClassLibrary2.csproj"; 
    template.Render(); 
#> 
<#+ 
    public class SampleTemplate : Template 
    { 
     public override string TransformText() 
     { 
      this.WriteLine("Hello, World!"); 
      return this.GenerationEnvironment.ToString(); 
     } 
    } 
#> 

Original Documentation

Wayback Machine

+1

謝謝,那篇文章是非常好的。 – MikeW 2012-04-17 11:06:04

+1

[鼓勵鏈接到外部資源,但請在鏈接上添加上下文,以便您的同行用戶可以瞭解它是什麼以及它爲什麼在那裏。如果目標站點無法訪問或永久脫機,請始終引用重要鏈接中最相關的部分](http://stackoverflow.com/help/how-to-answer)。 – 2016-05-24 17:25:06

+0

@ErikPhilips正確!頁面似乎已經死了(404)。幸運的是Wayback機器存在。 – TyCobb 2017-01-11 18:27:29

相關問題