tangible T4 Editor Blog

News, Tip and Tricks from the tangible T4 Editor team.

  • Home
  • Blog
  • Dependent T4 Templates – Automatically transform a T4 Template every time an input file is saved to generate new code

Dependent T4 Templates – Automatically transform a T4 Template every time an input file is saved to generate new code

This example shows how to attach a T4 Template file to a given input file so that the template is transformed each time the input file is saved.

 

Background

In most scenarios T4 template are used to transform the contents of a given file into a different format (C# code, XML, …). That way the T4 template file becomes dependent on the input file. The usual workflow then is: edit the input file, save the input file and transform the template again to make sure that all changes are transformed again.

From time to time one might simply forget to transform the template after editing the input file. That’s when it would be great to have the edit-save-generate procedure in one simple step. This is where the “Dependent Templates” feature of the tangible T4 Editor comes into play.

 

How To

In the Solution Explorer right click the file you want to be the input file for a dependent T4 template and choose “Add T4 Code Generator”.

image

 

The tangible T4 Editor then will add a new T4 template attached to the previously selected input file. This template contains some sample code about how to access the input file and generate output code from it.

 

image

 

The attached T4 template is transformed every time you edit and save the input file.

 

Remarks

The “Dependent Templates” feature is only available in the Pro-Version of tangible T4 Editor. You can buy the Pro-Version here.

Twitter Updates

Authorization on the site

For an authorized user opens up new possibilities

Login

Password