Can C++ projects use T4 in Visual Studio 2010?
T4 did not work for C++ projects in Visual Studio 2008 since it did not use msbuild for C++ projects. (Yes there开发者_运维百科 were workarounds) In Visual Studio 2010, C++ projects uses MsBuild, so do anyone know if C++ projects can use T4 in the same way as C# or VB?
The main integration mechanism for T4 in C# and Visual Basic projects is the TextTemplatingFileGenerator custom tool. Although in Visual Studio 2010 C++ projects now use MSBuild, they still don't support custom tools. As a workaround, you could use T4 Toolbox, which allows you to put a .tt file in a C# or Visual Basic project and have the files it generates added to your C++ project automatically.
I was interested in finding a way of using C++ with the T4 Templating myself and ended up just using the command line and the TextTransform.exe tool directly. You can then write a batch file that will call the TextTransform.exe against all your individual template.tt files, then just call the Batch file as part of your build in visual studio.
As I was learning it I decided to write up my findings in a tutorial which can be found here... http://www.gamelogicdesign.com/2012/04/12/c-code-generation-using-t4-templates/
Maybe this will be of use to people who would like to do something similar.
精彩评论