How to: Include Files in Text Templates
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.
To include a file in a text template
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.
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.
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:
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
On the Start menu, click Run.
In the Run dialog box, type regedit, and click OK.
The Registry Editor appears.
Browse to the location HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\TextTemplating\IncludeFolders, and click the node.
On the Edit menu, point to New, and then click Key.
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.
Right-click the new key, click New, and then click String Value.
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, …
Right-click Include0, and click Modify.
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)
For more information, see.