tangible T4 Editor Blog

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

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.



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.

Walking the Visual Studio Code Model with T4 Template (Design-Time Reflection)


It is common to use Reflection to explore namespaces, types and classes when running in a .NET application. But T4 Templates generate output code during Design Time. So there are no compiled assemblies yet that could be reflected or that ones available are from the last build and outdated.

In order to get information on what classes will be available in your assembly to be used inside a T4 Template, you need to access the Visual Studio CodeModel of the current project that is available at Design Time.


Access the Code Model

Using the Visual Studio Code Model you can access the following artifacts of your code at Design Time:
Types, Namespaces, Structures, Interfaces, Classes, Enumerations, Variables, Delegates, Properties and Functions. These Artifacts can be accessed via the CodeModel-Property of a EnvDTE.Project class or the Property “FileCodeModel” of a EnvDTE.ProjectItem.

Blog Series: Model Driven Development with T4 templates – Part 5


This is the last part of the blog series about some of tangible engineering’s contributions to a Model Driven Development process in software development. In this part we are going to create a basic generic user interface that allows users to explore and manipulate data from any domain specific model created as a Persistent Object Model.


Blog Series: Model Driven Development with T4 templates – Part 4


This part of the Model Driven Development blog series creates persistence layer (based on SQL Server) for the domain specific model built in Part 2 of the series using the C# code classes for Entity Framework 5.0 generated by a T4 template in Part 3.

The next blog post will create a basic user interface for interacting with the data objects and storing them in a SQL Server relational database.



Blog Series Overview

Part 1: Model Driven Development and Series Overview

Blog Series: Model Driven Development with T4 templates – Part 3

Part three of this blog series creates data objects based on the domain specific model we build in the previous part. Instead of writing all class code by hand we’re going to implement a reusable T4 template that transforms the model diagram into C# data classes for EntityFramework CodeFirst.

Following to this blog post we’re going to create data persistence layer based on this data classes and a basic user interface using another T4 template.




Twitter Updates

Authorization on the site

For an authorized user opens up new possibilities