Share via


T4 Text Template Directives

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Directives provide instructions to the text template transformation engine.

The syntax of directives is as follows:

<#@ DirectiveName [AttributeName = "AttributeValue"] ... #>

All attribute values must be surrounded by double quotation marks. If the value itself contains quotation marks, they must be escaped with the \ character.

Directives are typically the first elements in a template file or an included file. You should not place them inside a code block <#...#>, nor after a class feature block <#+...#>.

T4 Template Directive

<#@ template [language="VB"] [hostspecific="true|TrueFromBase"] [debug="true"] [inherits="templateBaseClass"] [culture="code"] [compilerOptions="options"] [visibility="internal"] [linePragmas="false"] #>

T4 Parameter Directive

<#@ parameter type="Full.TypeName" name="ParameterName" #>

T4 Output Directive

<#@ output extension=".fileNameExtension" [encoding="encoding"] #>

T4 Assembly Directive

<#@ assembly name="[assembly strong name|assembly file name]" #>

T4 Import Directive

<#@ import namespace="namespace" #>

T4 Include Directive

<#@ include file="filePath" #>

T4 CleanUpBehavior directive

<#@ CleanupBehavior processor="T4VSHost" CleanupAfterProcessingtemplate="true" #>

In addition, you can create your own directives. For more information, see Creating Custom T4 Text Template Directive Processors. If you use the Visualization and Modeling SDK to create a domain-specific language (DSL), a directive processor will be generated as part of your DSL.