Post

How to Transform T4 files (.tt) without Visual Studio

Microsoft integrates T4 text template support inside Visual Studio. However, you usually find it troublesome to transform such files outside Visual Studio (at command prompt or in your build process). In fact, you can even transform them without installing Visual Studio, because…Mono guys have a full open source implementation of that engine :)

Then how should you make use of the Mono assistance?

  1. Visit MonoDevelop source repository and grab two C# projects named Mono.TextTemplating and TextTransform, https://github.com/mono/monodevelop/tree/master/main/src/addins/TextTemplating
  2. Create a solution file and add these two. Compile them and now check the output of TextTransform project.

This project gives you a command line utility called TextTransform.exe.

About how to use it, simply execute it without any parameter and read its help. If you are familiar with Mono.Options, you can even learn that from its entry function, https://github.com/mono/monodevelop/blob/master/main/src/addins/TextTemplating/TextTransform/TextTransform.cs

Good luck.

© Lex Li. All rights reserved. The code included is licensed under CC BY 4.0 unless otherwise noted.
Advertisement