Share via

How to: Specify a Language in Text Templates

A template directive lets you specify the language that you want to use in your text template. You can specify Visual C# or Visual Basic. The language that you specify declares the programming language that is used for code statements, expressions, and class features in your text template. For more information, see Directive Syntax (Domain-Specific Languages).

By default, the C# language is used in the text template if you do not specify a langauge.


The generated text output that the transformation process creates can be in any language. The output does not have to be in the same language in which the text template is written; it does not even have to be in a programming language.

To specify the language to use in a template

  • At the top of the text template file, add a template directive and specify VB for Visual Basic or C# for Visual C#. If your text template already contains a template directive, add the language parameter to the existing one. If the template directive contains multiple parameters, the order does not matter. You can add the language parameter to the beginning or the end of the template directive.

    <#@ template language="VB" debug="true" #>
    <#@ template debug="true" language="C#"#>

    By default, the compiler for C# version 2 will be used. If you want to use another version of the compiler, and you know that the version is installed, you can specify the version number in the following manner:

    <#@ template debug="true" language="C#v3.5"#>


    In the 2010 version of Text Templating, this behavior has changed: the latest C# compiler is used by default, and version specifiers are ignored.

See Also


Walkthrough: Creating and Running Text Templates

Other Resources

Using Built-in Directives in Text Templates

Adding Code to Text Templates

Generating Artifacts By Using Text Templates

Change History




July 2008

Rewrote and refactored project.

Content bug fix.