The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Debugging T4 Text Templates

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Gareth Jones

Posts: 18
Nickname: garethj
Registered: Dec, 2005

Gareth Jones is a developer on Domain Specific Modelling Tools for Microsoft
Debugging T4 Text Templates Posted: Jan 9, 2006 3:51 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Gareth Jones.
Original Post: Debugging T4 Text Templates
Feed Title: GarethJ's WebLog
Feed URL: /error.htm?aspxerrorpath=/blogs/rss.ashx
Feed Description: Modeling User Experiences for DSL Tools in Visual Studio
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Gareth Jones
Latest Posts From GarethJ's WebLog

Advertisement
People often ask me about the best way to debug T4 templates.  This topic is covered in our new downloadable help file CTP, but I thought I'd get it up here in searchable form.
 
The first thing you need to do is to set the debug flag on the template directive of your template.
 
<#@ template debug="true" inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation" #>
 
If you're debugging a system-provided template rather than one of your own, this typically means that you'll need to copy the included portion of the template directly into the template file that's in your project.
 
Next you'll need to bring in the System.Diagnostics namespace (this isn't strictly necessary but it means you won't have to fully-qualify types).
 
<#@ import namespace="System.Diagnostics" #>
 
Finally, call Debugger.Break wherever you want to stop in your template.
 
<# Debugger.Break(); #>
 
When this gets hit, you should be asked whether you want to start a new instance of Visual Studio to debug or use an existing one.  You'll then be debugging within the generated-on-the-fly transformation class that implements your template.
 
If you're going to be doing a lot of debugging, there's also another technique available.
 
Open a second instance of Visual Studio.
Open your template files in the new instance.
Set breakpoints on the control code in the template just as though it was regular code.
Choose Tools/Attach to Process… and pick the original devenv.exe Visual Studio process.
Run your template in the original Visual Studio.
Your breakpoint should be hit.
 
I haven't actually tried it, but I believe these steps should also work for T4 templates used within GAT.
 
 

Read: Debugging T4 Text Templates

Topic: [Codezone] Deutschsprachige Visual Studio Express Image-Dateien, Codezone-Poems Previous Topic   Next Topic Topic: Community Launch Tomorow

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use