I'm using T4 for code generation. Its working well but one thing I'd like to do is some simple logging, I'm happy if this simply took the form of throwing messages into the Output window.
Does anyone know a way of doing this?
Alternatively, I know there exists Error() & Warning() methods for dumping stuff into the Error List pane, is there anything similar for dumping informational messages?
You can write run-time messages to the Output window using the Debug class or the Trace class, which are part of the System. Diagnostics class library. Use the Debug class if you only want output in the Debug version of your program. Use the Trace class if you want output in both the Debug and Release versions.
To debug a design-time text template, save the text template file, and then choose Debug T4 Template on the shortcut menu of the file in Solution Explorer. To debug a run-time text template, simply debug the application to which it belongs.
It's not exactly what you asked for but you can debug a T4 template from within visual studio, just right click "Debug T4 Template".
If you do this it's easy enough to keep the state you would be sending to the output window in a variable somewhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With