views:

10

answers:

1

Hi, everyone. I have an advanced T4 question and I'm hoping someone can help.

I've created a SQL-like DSL, and the scripts are saved in '.satsql' files in my C# projects, like so;

// contents of myqueries.satsql
SELECT <column t1.Id> FROM <table mytable t1>

I have a .tt file which loads the file and attempts to parse it. If it fails, I want to add an error to the Visual Studio error list, like so;

myqueries.satsql (1,8) error: unknown column 'xid' on table 't3'.
myqueries.satsql (2,9) error: bad reference: pid.

When the user clicks on the error, VS should open the 'myqueries.satsql' file and point the cursor at the appropriate line and character, just as it does for C# errors.

T4 already provides the void TextTransform.Error(string) method, but that doesn't seem to give me the opportunity to set the file, line, and character the way C# errors do.

Does anyone know a way for a T4 file to report an error in another file -- not the T4 file itself?

Many thanks,

Steve Cooper.

+1  A: 

You can use TextTransformation.Errors collection to report errors with file and line number information.

Oleg Sych
Worked perfectly! I was thrown because Errors is protected, so intellisense doesn't suggest it if you have a TextTransformation variable. I just needed to (A) create an abstract subclass of TextTransformation -- in my case, I called it SqlTextTransformation -- and (B) tell the TT file to use it with a line like <#@ template inherits="MyGenerator.SqlTextTransformation" #>
Steve Cooper