You can use text templates to generate reports as HTML documents for the Web. Text templates enable you to generate HTML and include valid HTML in text blocks. These templates ensure that any expressions and write statements will output valid HTML. The following procedure shows you how to create a template that generates HTML.
To create HTML from a text template
In Solution Explorer, right-click the text template file you want to edit, and then click Open.
The template opens in the editor.
Under your directives within your existing code, type in your html text.
For example:
<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation"#> <#@ ClassDiagramExample processor="ClassDiagramExampleDirectiveProcessor" requires="fileName='Sample.testcd'" #> <#@ output extension=".htm" #> <html> <h1>ModelClass</h1> <ul> <# foreach(ModelType type in this.ClassModel.Types) { #> <# if(type is ModelClass) {#> <li/><#=type.Name#> <# } #> <# } #> </ul> </html>Instead of double-clicking the generated text file to open it, right-click it and click View In Browser.
Your output should display with HTML formatting applied.
注意
To debug text templates you must set the debug parameter of the template directive. For more information, see How to: Debug Text Templates.
Security
For more information, see Security of Text Templates.
See Also
Concepts
Generating Specific Types of Artifacts from Text Templates