T4 Preprocessed Template Debugging Not Working - Visual Studio 2010 RTM

社会主义新天地 提交于 2019-12-05 04:14:31

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

oleg is the master I'd check ou http://www.olegsych.com/2008/09/t4-tutorial-debugging-code-generation-files/

It looks like your missing the debug="true" item in the template header which is necessary for debugging.

Also I would take a quick look at the following blog article which goes over T4 template debugging in great detail.

Update - With some help from the MSDN forums, it looks like the problem is with the #line directives that get added to the generated c# class. Commenting them out allows me to step through the code as expected. Is there any way to prevent these directives from being added to the generated class? With an ASP.NET page you can add the LinePragmas="false" parameter but that does not appear to have any effect on a T4 template. Any ideas?

The #line directives actually produce problems when debugging Preprocessed T4 templates (the debugger always searches for the *.tt file instead of the generated *.cs file). I wasn't able to find any option to turn of the generation of the #line directives. So I'm using the following VisualStudio Macro to get rid of them

Sub RemoveLineDirectives()
   DTE.ActiveDocument.Selection.SelectAll()
   DTE.ActiveDocument.Selection.ReplaceText("#line", "//#line")
End Sub

I'm always assigning the Macro to some short command within the command window

alias rl Macros.MyMacros.Module1.RemoveLineDirectives

So I'm able to remove the #line directives by simply invoking rl in the command window while the generated *.cs file is active, when I need to debug the Preprocessed T4 Template. After removing the #line directives debugging the generated template class works as expected.

Not the ideal solution but it works :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!