在VS2008中调试tt模板

时间:2009-12-01 14:32:43

标签: visual-studio-2008 templates subsonic3 t4

有没有办法调试tt文件?我已经安装了SubSonic3,除了StoredProcedures.tt之外,所有模板都可以完成它们的工作。 “运行自定义工具”后它仍为空。

3 个答案:

答案 0 :(得分:4)

这是一种简单的方法。

将这样的行添加到您的T4代码中:

System.Diagnostics.Debug.WriteLine("This is a debug message.");

从Sysinternals下载并运行DebugView。您的调试消息将出现在输出窗口中。

(在幕后,这些调用使用win32 OutputDebugString()。)

答案 1 :(得分:3)

阅读this article,解释两者的用法:

  • JIT调试器(通过在模板代码中放置Debugger.Break())和
  • 使用Visual Studio的第二个实例手动附加到Visual Studio进程

第二个对Windows XP之后的系统用户有用:

  • Vista的
  • 7
  • Server 2008
  • Server 2008 R2
  • ...

答案 2 :(得分:2)

使用以下命令启动模板:

<#@ template debug =“true”...

并添加:

System.Diagnostics.Debugger.Break();

到您的模板代码中以打入已编译的生成器类。