T4 Text Template Directives
A directive determines how the template will be processed.
The template directive contains all processing information needed to parse and compile the T4 text template. The should be only one template directive in a template. All further template directives, e.g. in included templates, will be ignored.
<#@ template [language="C#"] [compilerVersion="version"] [classname="class"] [codefile="file"] #>
The language attribute defines the programming language used in the control blocks and in the code file. OMS.Ice supports
C# and VB. This attribute is optional. The default language is
The compilerversion attribute specifies the .NET compiler version to use when compiling the generator. Possible values are
v3.5 or v4.0. This attribute is optional. If not set, the .NET runtime will choose the appropriate compiler version. To take the version specified in this attribute, you need to specify
CompilerSettings.Template in the generator options. The compiler version can be overwritten in the generator settings.
The compilerversion attribute is an extension to the Visual Studio T4 text template language.
This attribute can be used to provide a full qualified class name (namespace and class name) for the generated text generator class. This attribute is optional. The default value is
OMS.Ice.T4Generator. + the name of the template file without the extension. The generated text generator class is marked as partial and can be extended by our own partial class.
The classname attribute is an extension to the Visual Studio T4 text template language.
The codefile attribute defines the subsidiary code file containing a partial class to extend the generated text generator. The full qualified class name must match the class name given in the classname attribute.
The codefile attribute is an extension to the Visual Studio T4 text template language.
Assembly directives have the same meaning as the assembly reference in a Visual Studio project. You must add the appropriate assembly directives for all types you use inside your T4 text template.
<#@ assembly name="[assembly strong name|assembly file name]" #>
The name can be either the strong name of an assembly in the GAC or the absolute path to the assembly. The assemblies must be available at runtime.
The import directive is the equivalent to the using statement in C# or the
imports statement in VB.
<#@ import namespace="namespace" #>
The namespace attribute defines the namespace to import, e.g.
You can use the parameter directive to declare a property that can be used in the template. The values are passed through . You must use one parameter directive for each property. The parameters must be passed to the
Generate or GenerateToFile method of the template generator in the same sequence as they have been declared in the template.
<#@ parameter type="Full.TypeName" name="ParameterName" #>
The fully-qualified type name. If the namespace is referred by an import directive, the type name only would be sufficient. You can also use the build-in types such as
int (C#) or Integer (VB).
The name of the property. This can be any valid identifier.
A T4 text template can include other templates. The OMS.Ice – T4 Text Template Generator supports two different include modes.
Any template directive of an included template will be ignored. Assembly and import directives in included files will be treated as they were in the including template file. The usage of the include and parameter directives depends on the mode parameter.
<#@ include file="file" mode="mode" #>
The template file to include.
The mode attribute can be either inline or
method. Default value is inline.
If you choose the inline mode, the include directive will be replaced by the included template without any directives. The included text template will be treated as if it were part of the including template.
if the included template contains parameter directives, these parameters must be provided together with the parameters of the including template as described in the
Parameter Directive section.
The inline mode does not allow including templates recursively. That means, an included template must not include the including template.
If you select the method mode, the included template will be used as a method and the include directive will be replaced by a method call. All parameters defined in the included file will be used as method parameters. These
parameters can be provided by using the same parameter directives in the including file. Instead of using parameter directives, you can also declare the parameters as variables inside a standard control block of the including template. In this case, the variables
must be declared before the include directive.
The method mode allows including templates recursively. However, you will need a break condition in at least one control block to not end up in an endless loop.
The mode attribute is an extension to the Visual Studio T4 text template language.
The comment directive can be used to add comments to a template. Comments will be ignored when compiling the text template.
The comment directive is an extension to the Visual Studio T4 text template language.