Writing T4 templates

T4 templates can contain three types of content: literal text that will be copied directly to the output files, template directives which, just like a compiler directive, control how the TextTemplatingFileGenerator creates the file, and C# or VB code contained in what T4 calls a CONTROL BLOCK.

Image

Directives

T4 directives control how TextTemplatingFileGenerator creates the output file. They are wrapped inside <#@ and #> characters. The attributes must be included in quotation marks. The full list of directives and their attributes is available on MSDN (search for “Writing a T4 Text Template”), but here are the ones we’ll be using: ...

Get Fluent Entity Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.