Welcome Guest! To enable all features please Login or Register.



#1 Posted : Saturday, June 6, 2009 10:43:40 PM(UTC)
Rank: Administration

Groups: Administration
Joined: 3/24/2009(UTC)
Posts: 24

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)

In VS2010 you can set a breakpoint in code simply by writing a the command System.Diagnostics.Debugger.Launch();.

<#@ template debug="true" hostSpecific="true" #>
int i =1
// Now we set a breakpoint in VS2010 via Code
System.Diagnostics.Debugger.Launch(); // This is new in VS2010

In VS2008 you need to make sure registry settings are correct and you can then use the Command System.Diagnostics.Debugger.Break()

Set Value DbgJITDebugLaunchSetting in registry from 0x10 to 0x2
Key (x86 systems): HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework
Key (x64 systems): HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework

Sample Code for Breakpoint

<#@ template debug="true" hostSpecific="true" #>
int i =1
// Now we set a breakpoint in VS2010 via Code
System.Diagnostics.Debugger.Braek(); // This is how to set breakpoint in VS2008

Long Version:
For VS2010/VS2008:

1. Make sure your template includes the debug="true" attribute (see below)

2. Start an external VS to attach to first VS for debugging
On VS 2010 it is better to start another VS instance and attach it to the first as debugger.
Then the tempalte will break at the System.Diagnostics.Debugger.Break() statement when executed in the first VS.
Note that on some machines with VS2010 it is necessary to call System.Diagnostics.Debugger.Launch() before System.Diagnostics.Debugger.Break().

Alternative for VS2008 (Only):The best method to debug a T4 Tempalte is the following.

1. Make sure your template includes the debug="true" attribute (see below)

2. Insert a Call to Debugger.Break where needed

3. Make sure the following Key is changed in registry if you run Vista or later OS:
DbgJITDebugLaunchSetting value in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework key.
It’s default value on Windows Vista is 0×10. Change it to 0×2, which is the default value on Windows XP.
Note .NETFramework is ONE word - no spaces!
If you run 64 bit OS “Microsoft” part of the registry path mentioned in fact sits under and additional ‘Wow6432Node’ Folder also. So make sure you look at both locations. For VS2010 B2 it seems like a reboot is required also.

4. Use this template code to test
<#@ template debug="true" #>
this.Write("hello 1");
this.Write("hello 2");
5. After saving the file you get an info dialog to choose the debugger. There choose VS.

6. In an ideal world you now get the code that you just debugged. If not:
In VS got to Call Stack or press F11 to see the code (if not shown at the beginning).
Make sure you have the debug=true set in the template directive if issues.
If that doesn't help check the registry setting again (.NETFramework) has no spaces.

More info can be found here: http://www.olegsych.com/...g-code-generation-files/

Edited by user Friday, July 30, 2010 3:53:05 PM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF | YAF © 2003-2020, Yet Another Forum.NET
This page was generated in 0.153 seconds.

Authorization on the site

For an authorized user opens up new possibilities