Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get t4 files to build in visual studio?

When I build my c# solution the .tt files will not create the .cs file outputs. But if I right click the .tt files one at a time in solution explorer and select "Run Custom Tool" the .cs is generated, so the build tool setting is correct. What do I do to get the overall solution build to force the custom tool to run on the .tt files?

like image 327
P a u l Avatar asked Jan 01 '09 22:01

P a u l


People also ask

How do T4 templates work?

In Visual Studio, a T4 text template is a mixture of text blocks and control logic that can generate a text file. The control logic is written as fragments of program code in Visual C# or Visual Basic. In Visual Studio 2015 Update 2 and later, you can use C# version 6.0 features in T4 templates directives.


2 Answers

Paul, you can also generate code at build time with TextTransform.exe or Elton Stoneman's MSBuild task. Just keep in mind that behavior of the built-in directives, like assembly and include is different when T4 runs in Visual Studio vs. the command-line host.

like image 136
Oleg Sych Avatar answered Oct 24 '22 21:10

Oleg Sych


Answering my own question, they are supposed to be generated at design time as per this discussion:

https://web.archive.org/web/20081227142303/http://www.olegsych.com/2008/02/t4-template-directive/

like image 34
P a u l Avatar answered Oct 24 '22 21:10

P a u l