How to get t4 files to build in visual studio?

In Visual Studio 2017 (probably next versions too), you should add this in Pre-build event:

"$(DevEnvDir)TextTransform.exe" -out "$(ProjectDir)YourTemplate.cs" "$(ProjectDir)YourTemplate.tt"

p.s. The only solution that worked for me.

p.s.s. Change path to your template if it's located not in root project directory.


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.


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/