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 in the context of creating and using a complete text template, see Walkthrough: Creating and Running Text Templates.
See Also
Reference
Other Resources
Using Built-in Directives in Text Templates
Generating Artifacts By Using Text Templates
Change History
Date |
History |
Reason |
---|---|---|
July 2008 |
Rewrote and refactored project. |
Content bug fix. |