Debug TDS code generation templates


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.

How To

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>
	<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>
<# 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 for example.


Follow me on twitter @true_shoorik. Would be glad to discuss ideas above in comments.

Debug TDS code generation templates

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s