I was playing with Sitecore solution & projects setup and configuration, I faced a need to alter code generation logic used in it. We use TDS for content synchronization as well as it’s code generation engine build on T4 text templates.
While T4 is great for code generation, it is not as straightforward to debug them as it might be expected. So let me describe how to do this.
I have a solution with a set of projects. Each TDS project is referencing to the templates in a central location.
To start debugging I would ned following:
- Start two instances of Visual Studio (in my case 2015) with the project containing T$ templates.
- Add debug=”true” to a template
<#@ template language="C#" debug="true" hostSpecific="true" #></pre> <ul> <li>Add a following line of code to the template. <em>Note: that items template will not be triggered is debug added to a header template, so you would nee to add ерш line to one you trying to test</em></li> </ul> <pre> <# System.Diagnostics.Debugger.Launch(); #>
- On TDS project that you using run "Regenerate Code for all items"
- Debugger windows will appear as soon as code would hit "Debugger.Launch()" where you would need to select another instance of Visual Studio which runs your templates.
Done: Once the debugger loads itself - you are ready to dive in your code. Here is what you would be able to see in glassv3header.tt for example.
Follow me on twitter @true_shoorik. Would be glad to discuss ideas above in comments.