Debugging T4 Template VS2013 - t4

I am trying to debug T4 template in Visual Studio 2013. But I don't see "Debug T4 Template" option when I right click on my .tt file in solution explorer.
What do I need to do to be able to see that option and to successfully debug the template?

Sometimes you have to wait for the Error List to Load till you can Debug T4.

Related

How to execute T4 template files in Visual Studio For Mac?

I am unable to run text templates in Visual Studio for Mac or visual studio code. I tried:
VS > Right click project > Tools > Process T4 templates > (No Templates Found)
I also went to Visual Studio top menu > Extensions > (Search for T4) > IDE Extensions > Text Templating v8.10.6 is installed.
I am trying to use the *.tt template from linq2db.SqlServer.. But running any basic T4 template would let me know the TextTemplatingFileGenerator is at least working. There the documentation states:
Make sure that custom tool for your tt file set to TextTemplatingFileGenerator, otherwise it will not run
Though it doesn't explain how to actually accomplish this task?
I also installed TT-Processor into visual studio code. I was also unable to execute the *.tt file. In this case I did not see an execute/run command when I right clicked a *.tt file.
Microsoft answered the question for me. As I already mentioned, the part that nobody talks about is the answer to this:
Make sure that custom tool for your tt file set to TextTemplatingFileGenerator, otherwise it will not run
In visual studio right click the *.tt File > Properties > Custom Tool > Choose "TextTemplatingFileGenereator"
Now visual studio will find the *.tt file when you Right click the project > Tools > Process T4 templates
Arguably, this experience should be improved to default to this behavior to fit the philosophy of "fall into the pit of success".

VS 2017 Debug Error

I'm getting an error when I try to inspect variables in my VS 2017 C# code. The errors started with an upgrade.
Native View To inspect the native object, enable native code debugging.
The a google search suggests the following fix, but I cannot find this option on y Project-Properties-Debug page.
To enable debugging of unmanaged code
With a project selected in Solution Explorer, on the Project menu, click Properties.
Click the Debug tab.
Select the Enable unmanaged code debugging check box.
Try This
add the following to your profile in launchsettings.json
"nativeDebugging" : true
I have also read some posts it says like
starting in Visual Studio 2017 version 15.5 you should be able to set <EnableUnmanagedDebugging>true</EnableUnmanagedDebugging> in your .csproj file.

How to Create Visual Studio 2013 Extension

I am interested to create a visual studio 2013 extension. I have gone through some of the msdn links. I am looking for adding one extra option when you right click on any .cs file/folder/project/solution, then on clicking that option some processing will be done on the .cs file/s. And lastly when the processing is done, the output should get print on a result window.
Edit -> Or May be Right Click -> Processing on .cs files -> open a windows form.
Similar to what happens when we do - Search/Replace in all files.
I know there are some options like - VSIX Project template, Editor templates, Visual Studio Package and Visual Studio Shell Isolated.
But i am not getting which one will help me out.
Any thoughts on this?
Thanks,
jash
I got the answer - we have to create a new VS package

Debugging T4 Template in VS 2010 Crashes IDE

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?
in Visual Studio 2010 you need to call Debugger.Launch() before Debugger.Break().
Instead of using System.Diagnostics.Debugger.Launch(); or Break(), attach the debugger manually.
In a second instance of vs2010,
open the T4 template you want to
debug (just the .tt file is fine)
Go to Debug -> Attach to Process and find the original devenv.exe
process
Add a regular breakpoint
(red ball) to the place you want to
start the debug (in the second
vs2010 still)
Go to the original
vs2010, save the .tt file and...
bingo! The second instance of vs2010
will debug your template.
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(); #>
You also need debug=true:
<##template debug="true" #>
System.Diagnostics.Debugger.Launch();
Debugger.Break();
http://msdn.microsoft.com/en-us/library/bb126338.aspx
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.

Setting a breakpoint in a T4 template

I'm trying to debug the execution of a T4 template in Visual Studio 2008.
All the information I'm finding on debugging T4 templates in Visual Studio 2008 say that you can set a breakpoint (red dot) in the template as if it were a regular code file. I have the Clarius T4 code highlighter installed, so my T4 template is colored, but I can't set a breakpoint. When I click in the margin nothing happens.
I've tried Debugger.Break(), and it launches a new instance of VS.NET, but it can't load the code from my template. I get a dialog that says "There is no source code available for the current location." This happens if I have the same project loaded in the another instance of if I spin up a new instance.
What gives?
Set the following:
<## template debug="true" hostSpecific="true" #>
<## import namespace="System.Diagnostics" #>
Then in your template
Debugger.Launch();
VS will kick off the JIT debugger in a new instance of VS 2010
In Visual Studio 2013:
Set a breakpoint in the .tt file
Right-click the .tt file in the solution explorer
Select "Debug T4 Template"
Done!
No attaching a second instance of Visual Studio needed.
OK- figured it out. Launching a new instance is not an option, regardless of what Oleg's article says. (No diss to Mr. Sych, his blog is gospel for T4 code generation!)
Start a second instance of Visual Studio,
Open a file (any file) so the Debug menu shows up.
Select "Attach to Process..." and select the other VS.NET instance
Save your template in the attached instance of VS.NET (or right-click and select Run Custom Tool)
Voila.
Make sure that you turn on the debug option in the template directive:
<## template language="C#" debug="true" #>
This makes T4 save the source code and symbol files necessary for debugging in Visual Studio.

Resources