How to: Generate Templates from Templates By Using Escape Sequences
You can create a text template that creates another text template as its generated text output. To do this, you must use escape sequences to delineate the text template tags. If you do not use escape sequences, your generated text template will have a pre-defined meaning. For more information about using escape sequences in text templates, see How to: Use Escape Sequences in Text Templates.
To generate a text template from within a text template
Use the backslash (\) as an escape character to produce the necessary markup tags within the text template for directives, statements, expressions, and class features in a separate text template file.
For more information, see Adding Code to Text Templates.
\<#@ directive \#> \<# statement \#> \<#= expression \#> \<#+ classfeature \#>
Example
The following example uses escape characters to produce a text template from a text template. The output directive sets the destination file type to the text template file type (.tt).
\<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation"\#>
\<#@ ClassDiagramExample processor="ClassDiagramExampleDirectiveProcessor" requires="fileName='Sample.testcd'" \#>
<#@ output extension=".tt" #>
\<#
foreach(ModelType type in this.ModelRoot.Types)
{
\#>
\<#= type.Name \#>
\<#
}
\#>
The generated text output is a text template.
<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation"#>
<#@ ClassDiagramExample processor="ClassDiagramExampleDirectiveProcessor" requires="fileName='Sample.testcd'" #>
<#
foreach(ModelType type in this.ModelRoot.Types)
{
#>
<#= type.Name #>
<#
}
#>
See Also
Other Resources
Generating Artifacts By Using Text Templates
Using Built-in Directives in Text Templates
Change History
Date |
History |
Reason |
---|---|---|
July 2008 |
Rewrote and refactored project. |
Content bug fix. |