使用 C# 运行 T4 模板 [英] Running a T4 template using C#

查看:57
本文介绍了使用 C# 运行 T4 模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有生成 cs 文件的 T4 模板 (mycode.tt).我通常右键单击 tt 文件并选择 RunCustomTool,它在内部接受一个 xml 文件并为我生成代码.现在我想使用 c# windows 应用程序运行自定义工具.所以点击一个按钮我想运行自定义工具.是否可以从 c# 运行 CustomTool.

I have T4 template (mycode.tt) which generates a cs file. I usually right click the tt file and select RunCustomTool which internally takes an xml file and generate code for me. Now i want to run the custom tool using a c# windows application. So onclick of a button i want to run the Custom Tool . Is it possible to run the CustomTool from c#.

我有 2 个 tt 文件,其中一个没有代码隐藏 cs 文件.但是另一个附加了一个 .cs 文件,我正在从第一个 .tt 文件调用第二个文件的 TransformText() 方法.所以我需要调用第一个文件.所以我不能使用 TransformText() 方法.有没有办法动态调用textTemplate文件?

I have 2 tt files and one of them doesn't have a codebehind cs file. But another has a .cs file attached with it and i am invoking the second file's TransformText() method from the first .tt file. So i need to invoke the first file.So i cannot use the TransformText() method. Is there a way to dynamically call the textTemplate file ?

推荐答案

我推荐上面@jb_ 回答的预处理路线.

I'd recommend the preprocessed route as answered above by @jb_.

作为替代方案,如果您需要模板在没有编译步骤的情况下仍可编辑以用于您的自定义 C# 应用程序,并且该应用程序将仅与 Visual Studio 一起部署在计算机上,您可以编写自定义主机.

As an alternative, if you need your templates to still be editable without a compile step for use with your custom C# application, and the application will only be deployed on machines alongside Visual Studio, you can write a custom host.

http://msdn.microsoft.com/en-us/library/bb126519.aspx

这篇关于使用 C# 运行 T4 模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆