Articles Archive

T4 Architecture


This article provides an in-depth look at the architecture of T4 template transformation process, discusses some constraints that limit template design, describes techniques that can be used to work around these limitations and points out some (sometimes undocumented) mechanisms for making your T4 templates more powerful.

T4 Template Design


This article discusses design challenges developers face as complexity of their T4 templates increases; defines qualities of a reusable T4 templates; discusses techniques that can be used to achieve these qualities and compares their pros and cons.

Understanding T4: <#@ property #> directive


This article describes the purpose and implementation mechanics of the T4 <#@ property #> directive.

How to generate multiple outputs from single T4 template


For some code generation tasks, like generating SELECT stored procedures based on indexes of a given database table, number of output artifacts may not be known upfront. Because T4 was designed to generate a single output file from one template file, developers are forced to generate multiple code artifacts in the same source file. This conflicts with the widely used practice of using one source file per code artifact. This article demonstrates how to work around this limitation of T4, generate multiple files from a single template and automatically add them to a Visual Studio project.

Code Generation with Visual Studio Templates


This article provides an overview of Visual Studio Templates, demonstrates how to create a project item template for a T4 file and includes a ready-to-use T4 item template.

How to use T4 to generate strongly-typed AzMan wrapper


This article provides a brief overview of AzMan and demonstrates how several existing APIs can be used to perform authorization checks in .NET applications. It then discusses shortcomings of the current APIs and demonstrates how T4 templates can be used to generate a set of C# classes and enumerations that wrap AzMan COM API and allow application developers to write strongly-typed authorization code.

How to use T4 to generate CRUD stored procedures


This article demonstrates how to use SMO and T4 templates to generate CRUD stored procedures in Visual Studio and integrate them in a database project.

How to use T4 to generate Decorator classes


This article demonstrates how to use Introspection and T4 templates to generate C# Decorator classes in Visual Studio.

How to use T4 to generate .config files


This article demonstrates how to create and use a simple T4 template to generate App.config files for development, testing and production environments in Visual Studio.

How to create a simple T4 template


This article demonstrates how to create and use a simple T4 template to generate C# code in Visual Studio without building a DSL or a Guidance package.