Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual Studio SDK
 How to: Generate Code from Text Tem...
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Domain-Specific Language Tools 
How to: Generate Code from Text Templates 

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

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

    The file opens in the editor.

  2. 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#>
    <#
        }
    #>
    
  3. On the Solution Explorer toolbar, click Transform All Templates. For more information, see How to: Run Text Templates.

Security

For more information, see Security of Text Templates.

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker