Articles Archive
Extending T4: <#@ xsd #> directive
This article describes a custom T4 directive processor for converting XML schema definitions into .NET classes, which allows using strongly-typed code to extract information from various XML files. In particular, this simplifies creating custom T4 code generation templates for LINQ to SQL .dbml files and ADO.NET Entity Framework .edmx files. The article includes links to ready to use xsd directive processor and sample source code.
Simplifying WCF: Using Exceptions as Faults
This article describes an overview of error handling in WCF, discusses its advantages and drawbacks and shows how to extend WCF to marshal .NET exceptions as SOAP faults. Ready-to-use source code and examples are available for download.
T4 template for generating SQL view from C# enumeration
Database tables often contain columns that store codes, or values with special meaning. In application code, these special values can be encapsulated as enumerations. This article demonstrates how to use T4 code generation templates and Visual Studio CodeModel API to generate SQL views that encapsulate the special values for use in SQL code.
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.
Find It Quickly
Find what you're looking for quickly by using our keyword search. Can't find it? Try our links below.


