Sign in
[Profoundly Esoteric Image]
GarethJ's WebLog - Code generation and abstraction
Translate This Page
Translate this page
Powered by
Microsoft® Translator
Options
Blog Home
Email Blog Author
Share this
RSS for posts
RSS for comments
Search
Tags
Built with DSL Tools
Code Generation
Code samples
Community
DSL Tools
Enterprise Development
Fun
Metablog
Modeling
Pages
Razor
Sounding off
SP1
T4
Tech thrills
The real world
UML
Visual Studio
Visual Studio 11 Beta
Visual Studio 2012
VSX
Archive
Archives
June 2012
(1)
April 2012
(1)
November 2011
(1)
September 2011
(1)
June 2011
(1)
May 2011
(1)
April 2011
(1)
March 2011
(2)
January 2011
(6)
December 2010
(2)
August 2010
(1)
June 2010
(1)
April 2010
(2)
March 2010
(1)
October 2009
(1)
September 2009
(6)
May 2009
(3)
February 2009
(4)
January 2009
(2)
November 2008
(6)
October 2008
(5)
September 2008
(3)
July 2008
(2)
May 2008
(4)
April 2008
(4)
March 2008
(2)
February 2008
(9)
January 2008
(9)
December 2007
(6)
November 2007
(1)
October 2007
(3)
September 2007
(5)
August 2007
(3)
July 2007
(3)
June 2007
(5)
May 2007
(6)
April 2007
(1)
March 2007
(2)
February 2007
(5)
January 2007
(3)
December 2006
(2)
November 2006
(2)
October 2006
(3)
September 2006
(3)
August 2006
(2)
July 2006
(2)
June 2006
(5)
May 2006
(1)
April 2006
(3)
March 2006
(1)
February 2006
(3)
January 2006
(3)
December 2005
(10)
November 2005
(5)
October 2005
(3)
September 2005
(8)
August 2005
(2)
July 2005
(4)
June 2005
(5)
May 2005
(6)
April 2005
(2)
March 2005
(4)
February 2005
(4)
January 2005
(5)
December 2004
(9)
November 2004
(4)
October 2004
(13)
August 2004
(4)
July 2004
(2)
Debugging T4 Text Templates
MSDN Blogs
>
[Profoundly Esoteric Image]
>
Debugging T4 Text Templates
Debugging T4 Text Templates
GarethJones
9 Jan 2006 5:16 AM
Comments
5
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.
5 Comments
Modeling
,
DSL Tools
,
T4
Blog - Comment List MSDN TechNet
Comments
Loading...