4

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?

Community
  • 1
  • 1
Arve
  • 7,284
  • 5
  • 37
  • 41

2 Answers2

3

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.

Oleg Sych
  • 6,548
  • 36
  • 34
2

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.

  • 1
    That link doesn't work (in fact the entire blog appears to have been zapped). Luckily the Way Back Machine has the internet covered: http://web.archive.org/web/20120803024751/http://www.gamelogicdesign.com/2012/04/12/c-code-generation-using-t4-templates/ – kornman00 Apr 19 '13 at 20:15