How to: Generate Errors and Warnings from Text Templates
You can generate custom error and warning messages from text templates and display them in the Error List window. You can use this technique to customize the behavior of your text templates for your language users.
To add error or warning messages as text template output
In Solution Explorer, right-click the text template file that you want to edit, and then click Open.
The file opens in the editor.
Add the following code with the Error and Warning methods to the template:
<# string name = null; if(string.IsNullOrEmpty(name)) { //raise an error, this will appear in the error list Error("I have no name."); } name = "short"; if(name.Length < 6) { //raise a warning, this will appear in the error list Warning("I have a really short name."); } #>
<# Dim name as string = "" If string.IsNullOrEmpty(name) Then 'raise an error, this will appear in the error list Me.Error("I have no name.") End If name = "short" If name.Length < 6 Then 'raise a warning, this will appear in the error list Me.Warning("I have a really short name.") End If #>
If the template throws any unhandled exceptions, they also appear in the Error List window and stop execution of the template.
To learn how to use errors and warnings within the context of creating and using a complete text template, see Walkthrough: Creating and Running Text Templates.
Hinweis
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
Using Built-in Directives in Text Templates
Generating Artifacts Using Text Templates