Yousef
Yousef

Reputation: 906

t4 templates per template TransformOnBuild setting

I would like to automatically execute one of the .tt files when my project is built, but not the others. Is it possible to set the TransformOnBuild property on specific .tt files instead of project wide? Or another method to accomplish this?

Upvotes: 2

Views: 1409

Answers (2)

Yousef
Yousef

Reputation: 906

I have decided to add a custom pre build step to generate the .tt files needed:

<Exec Command="&quot;%PROGRAMFILES(x86)%\Common Files\microsoft shared\TextTemplating\10.0\TextTransform.exe&quot; template.tt -out template.cs" />

This method also allowed me to easily pass parameters (defined in the project file) to the template with -a; another problem I was facing.

Upvotes: 6

Kallex
Kallex

Reputation: 528

Answering as another method to accomplish this.

  1. You could change your .tt as TextTemplatingFilePreprocessor (descibed better here: http://www.olegsych.com/2009/09/t4-preprocessed-text-templates/).
  2. Create small command line tool that executes the preprocessor on pre-build event.

The first link includes this example, but it describes the use of preprocessed class: http://blogs.clariusconsulting.net/pga/vs10-beta-1-t4-preprocessing-part-2/

Upvotes: 0

Related Questions