views:

120

answers:

2

I am attempting to debug a preprocessed T4 template and I am not able to step into the class created by running the preprocessed template. I am able to create an instance of the class but as soon as I try to step into while debugging, a new window pops up that says

No source available. There is no source code available for the current location.

My understanding was that preprocessed templates could be debugged just like a normal c# class, is this not correct? Is there anything in particular that you need to do to be able to step into the class defined by a preprocessed template?

Here is a very simple template and the calling code that I am experience the problem with:

TestPreprocessedTemplate.tt:

<#@ template language="C#" debug="true" #>
Hello <# Write("World"); #>

Test Code:

var template = new TestPreprocessedTemplate();
string test = template.TransformText();

Edit - Added the debug="true" statement per the suggestion below, still have same problem.

Update - I also posted this question on the MSDN forums and received response from a MS employee that indicated yes what I described above should indeed work. Anyone else ever run into this problem?

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?

+1  A: 

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.

JaredPar
I had tried that as well, and just to make sure I just tried it again, ran the template and tried to debug it again. Same issue...As for the article, I had come across that before and I am able to debug a normal t4 template, but when I try to debug the preprocessed template I am not able to.
+1  A: 

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/

James Fleming