Domain-Specific Language Tools 
How to: Import Namespaces in Text Templates 

You can add an import directive to text templates and use that directive to specify the namespaces that you want to use in those text templates. For more information, see Directive Syntax (Domain-Specific Languages).

You can add a namespace to a text template to avoid having to use fully qualified names in the code in your text template.

To import a namespace

  1. In Solution Explorer, right-click the text template file that you want to edit, and then click Open.

    The template opens in the editor.

  2. Specify a namespace using the import directive, as shown in the following example:

    <#@ import namespace = "System.Collections.Generic" #>

Example

The following example demonstrates how to use the import directive.

C#
<#@ import namespace = "System.Collections.Generic" #>
<#
    List<string> names=new List<string>();
#>
Visual Basic
<#@ import namespace = "System.Collections.Generic" #>
<#
    Dim names As List(Of String) = New List(Of String)
#>

To debug text templates, you must set the debug parameter of the template directive. For more information, see How to: Debug Text Templates.

Security

For more information, see Security of Text Templates.

See Also

Tags :


Page view tracker