Export (0) Print
Expand All

How to: Include Files in Text Templates 

Visual Studio 2005

You can use the include directive to include files in text templates. When you add the include directive to a text template, the included file is processed as if it were included verbatim in the text template. The include directive helps you to organize your code, and to reuse your code in different text templates. For more information, see Directive Syntax (Domain-Specific Languages).

To include a file in a text template

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

    The template opens in the Text Editor.

  2. Add an include directive to the template, and specify the name of the file that you want to include in the file parameter. For example, your code will look like the following:.

    <#@ include file="c:\test.txt" #>

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

Adding Include Directories to the Registry

When you use the include directive, you usually specify the full path and the name of the file to include. If you are including a large number of files in your text templates, you can add include directories to the registry. After you add include directories to the registry, you can specify the file name only, without the path, for the file parameter in the include directive.

The location for include directories in the registry is:

Caution noteCaution

Incorrectly editing the registry can severely damage your system. Before making changes to the registry, back up any valued data on the computer.

To add an include directory to the registry

  1. On the Start menu, click Run.

  2. In the Run dialog box, type regedit, and click OK.

    The Registry Editor appears.

  3. Browse to the location HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\TextTemplating\IncludeFolders, and click the node.

  4. On the Edit menu, point to New, and then click Key.

  5. Type the file extension of your domain-specific language as the name of the new key.


    The file extension is the one that you specified in the Domain-Specific Language Designer Wizard.

  6. Right-click the new key, click New, and then click String Value.

  7. Type Include0 for the name of the new string.


    You can have more than one include folder for each file extension. To add multiple folders, add multiple string values to the key, and name them Include0, Include1, Include2, …

  8. Right-click Include0, and click Modify.

  9. In the Edit String dialog box, in Value data, type the path of the folder that you want to check for included files. For example, type C:\TextTemplateUtilities.

    When you finish, your new registry key should look like this:

    Name Type Data



    (value not set)



    <Your Path>


For more information, see Security of Text Templates.

See Also

Community Additions

© 2015 Microsoft