将现有文件转换为运行时模板:

  • “自定义工具”属性设置为 TextTemplatingFilePreprocessor。【文本模板的自定义工具是TextTemplatingFileGenerator
  •  

运行时模板的tt的内容如下:

 1 <#@ template language="C#" #>
 2 <#@ assembly name="System.Core" #> 
 3 <#@ import namespace="System.Linq" #>
 4 <#@ import namespace="System.Text" #>
 5 <#@ import namespace="System.Collections.Generic" #>
 6 
 7 <h2>Sales figures</h2>
 8 <table>
 9 <# foreach (var item in m_data) 
10    // m_data is declared in MyWebPageCode.cs
11    { #>
12       <tr><td> <#= item.Key #> </td>
13           <td> <#= item.Value #> </td></tr>
14 <# } // end of foreach
15 #>
16 </table>
View Code

相关文章: