How to stop T4 from executing every time I switch to another tab?

Viewed 5095

When I edit T4, the script is executed every time I switch to another file. It is OK for quick simple scripts, but some scripts take long time to execute. Is there a way to disable this behavior? I want the script to run only when I save T4 file or manually choose "Run Custom Tool" from the menu.

6 Answers

I have found it useful when developing a T4 template to use the following code snippet at the top of the T4 file:

<# //throw exception to halt execution during development
    throw new Exception();
#>

If there are errors when the T4 is saved, they will be displayed, otherwise, a message displayed:

Error Running transformation: System.Exception: Exception of type 'System.Exception' was thrown.

Then comment out the exception when you're ready to actually generate the T4 output.

Related