简体   繁体   English

从模板生成多个输出文件

[英]Generating more than one output file from a template

Hi I am writing a custom template generator for my xml file. 嗨,我正在为我的xml文件编写一个自定义模板生成器。 I was wondering if you guys can tell me a way I can generate more than one output file from the template under the same template. 我想知道你们是否可以告诉我一种可以从同一模板下的模板生成多个输出文件的方法。

The no of file should depend on the no of xml files I input 文件数应取决于我输入的xml文件数

If I want to generate the c# class for a.xml I am doing something like this 如果我想为a.xml生成c#类,我正在做这样的事情

<#= XmlToCsGenerator.Xml(this.Host.ResolvePath("a.xml")) #>

where my function XmlToCsGenerator.Xml(string path) returns the string to be written into the file. 我的函数XmlToCsGenerator.Xml(string path)返回要写入文件的字符串。

Thanks in advance 提前致谢

Damien Guard's approach detailed here: http://damieng.com/blog/2009/11/06/multiple-outputs-from-t4-made-easy-revisited is a good one too. Damien Guard的方法在这里详细介绍: http : //damieng.com/blog/2009/11/06/multiple-outputs-from-t4-made-easy-revisited也很不错。 This is very close to the approach used in the Entity Framework's use of T4 in the .Net 4.0 product. 这与.Net 4.0产品中Entity Framework使用T4所使用的方法非常接近。

Have a look at this article/sample: 看一下这篇文章/样本:

http://www.olegsych.com/2008/09/t4-tutorial-creating-complex-code-generators/ http://www.olegsych.com/2008/09/t4-tutorial-creating-complex-code-generators/

Author has illustrated creating multiple delete procedures (corresponding to multiple tables) for single template. 作者演示了为单个模板创建多个删除过程(对应于多个表)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM