Debugging T4 Template in VS 2010 Crashes IDE

2019-03-12 11:42发布

I'm trying to debug a slightly-modified version of the ADO.NET POCO Entity Generator template using the directions Oleg Sych published a few years back. I modified the DbgJITDebugLaunchSetting key as recommended.

I get a dialog indicating that a user-defined breakpoint has been hit. However, rather than being presented with the option to debug with a new instance of VS 2010, the original instance of VS 2010 just crashes and auto-restarts.

Is it possible to debug T4 templates with VS 2010?

5条回答
在下西门庆
2楼-- · 2019-03-12 11:52

Instead of using System.Diagnostics.Debugger.Launch(); or Break(), attach the debugger manually.

  1. In a second instance of vs2010, open the T4 template you want to debug (just the .tt file is fine)
  2. Go to Debug -> Attach to Process and find the original devenv.exe process
  3. Add a regular breakpoint (red ball) to the place you want to start the debug (in the second vs2010 still)
  4. Go to the original vs2010, save the .tt file and... bingo! The second instance of vs2010 will debug your template.
查看更多
小情绪 Triste *
3楼-- · 2019-03-12 11:56

in Visual Studio 2010 you need to call Debugger.Launch() before Debugger.Break().

查看更多
可以哭但决不认输i
4楼-- · 2019-03-12 11:58

To add to andrecarlucci's solution, if you save the file, you will be prompted to reload it in the second instance of Visual Studio before you can debug it. If you don't need to make further changes but need to debug it multiple times, you don't have to save every time in order to break into the code. You can simply click the Transform All Templates button on the Solution Explorer toolbar in the original instance of Visual Studio.

查看更多
迷人小祖宗
5楼-- · 2019-03-12 12:09

Final solution which works for me:

regedit:

Key (x86 systems): HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework

Key (x64 systems): HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework

value: DbgJITDebugLaunchSetting

data: 0x2

tt template:

<#@ template debug="true" hostSpecific="true"  #>
<# System.Diagnostics.Debugger.Launch(); System.Diagnostics.Debugger.Break(); #>
查看更多
Summer. ? 凉城
6楼-- · 2019-03-12 12:10

You also need debug=true:

<@#template debug="true" #> System.Diagnostics.Debugger.Launch(); Debugger.Break();

http://msdn.microsoft.com/en-us/library/bb126338.aspx

查看更多
登录 后发表回答