You can use text templates to generate code output, including Visual C# and Visual Basic files. To generate code files, you must include valid code blocks, and you must ensure that any expressions and write statements generate valid code.
To generate code output from a text template
-
In Solution Explorer, right-click the text template file that you want to edit, and then click Open.
The file opens in the editor.
-
Under the directives within your existing code, type in your code.
The following example illustrates how to generate code in Visual C#:
|
<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation"#>
<#@ MyLanguage processor="<YourLanguageName>DirectiveProcessor" requires="fileName='Sample.mmm'"#>
<#@ output extension=".cs" #>
<#
foreach(ModelType type in this.ModelRoot.Types)
{
#>
<#= type.Name#>
<#
}
#>
|
-
On the Solution Explorer toolbar, click Transform All Templates. For more information, see How to: Run Text Templates.
Security
See Also