本文介绍了如何在VS C ++项目中使用T4代码生成模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IDE在C#项目下可以自动识别T4模板文件,但是我不知道如何将它们集成到C ++项目中(除了使用make文件).

T4 template files are automatically recognizable by the IDE under C# projects, but I have no clue on how they can be integrated into C++ projects (other than using make files).

有什么想法吗?

推荐答案

T4模板文件可以集成到C ++项目中,但是比C#/VB项目要花更多的精力.在您的C ++项目中创建一个新的文本文件,并将其扩展名为.tt.然后照常编写模板.然后,C ++项目需要进一步的工作才能使其转换模板.我得到它的快速而肮脏的方法是添加一个自定义生成步骤,并将其直接调用为"C:\ Program Files \ Common Files \ Microsoft Shared \ TextTemplating \ 1.1 \ TextTransform.exe".我发现的另一种方法是添加自定义MSBuild任务.可以在此处找到说明

T4 Template files can be integrated into C++ projects, but it's a bit more work than with a C#/VB project. Create a new text file in your C++ project and give it a .tt extension. Then write your template as normal. A C++ project then needs further work to get it to transform the templates. The quick and dirty way I got it to work was to add a custom build step and have it call "C:\Program Files\Common Files\Microsoft Shared\TextTemplating\1.1\TextTransform.exe" directly. Another way I found was to add a custom MSBuild task. Instructions can be found here

此页面提供了更多信息,并提供了有关使用T4代码的其他页面的良好链接.世代.

This page has more information and some good links to other pages on using T4 code generation.

这篇关于如何在VS C ++项目中使用T4代码生成模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 15:59