T4 tip (debug)
while I was writing the post on T4 debugging (here),
I had show how to use System.Diagnostics.Debugger.Break()
in order of getting the debugger stop.
actually there is 2 problem with this pattern:
- the break point remain active while no debugger is attached.
- it cause VS to crash when ever saving the t4, when the debugger doesn't attached.
Solution
we can overcome those issues by changing the pattern to match the following:
Code Snippet
- if (System.Diagnostics.Debugger.IsAttached)
- System.Diagnostics.Debugger.Break();
Summary
using the IsAttached pattern will prevent the breaking point activation
as long as the no debugger is attached.