【问题标题】:T4 Template debugger shows incorrect lines while multiple TT files includedT4 模板调试器在包含多个 TT 文件时显示不正确的行
【发布时间】:2011-10-24 09:00:39
【问题描述】:

我正在尝试使用 VS2010 Professional , windows 7 调试以下 T4 模板文件。

但调试器没有突出显示文件中的正确行:“Texttemplate2.tt”

文件 1:文件 1.tt

<#@ template debug="true" hostspecific="true" language="C#" #>

<#@ include file="Texttemplate2.tt"  #>

<#

System.Diagnostics.Debugger.Launch();


    int a= 10;

    Write("ASS");

    GetProperty("User","UserName");

#>

文件:Texttemplate2.tt

<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ assembly name="System.Xml" #>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.IO" #>
<#+

 public void Load()
    {
        string doc=null;
        if(doc == null)
        {
            string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);
            string absolutePath = Path.Combine(templateDirectory,"../../App_Data/EntityUI_MetaData_Appsettings.xml");
        }
    }
 public string GetProperty(string Entity, string prop)
    {
         Load();
         string node="none";

         if (node != "0" )
         {
            if (node == Entity )
              {
                return node;
              }
         }
        return null;
    }
 #>

让我详细解释一下这个问题。我已经创建了上面的两个T4模板文件。现在我想调试我的 T4 模板文件“File1.tt”代码(不是生成的代码)。我做了什么我启动了调试器

System.Diagnostics.Debugger.Launch();

并设置断点

int a= 10;

。现在按 F5 会导致我的断点被命中。

int a= 10;

它现在以黄色作为背景,黄色箭头作为左侧突出显示。之后按 F11 直到到达

GetProperty

当这个方法被调用时,你会注意到黄色箭头,表示当前正在执行的语句没有突出显示。

意思是,假设 Line:20 是下一个执行语句,调试器会在 texttemplatefile2.tt 中高亮 line:10

【问题讨论】:

    标签: c# asp.net visual-studio-2010 t4


    【解决方案1】:

    我也遇到了同样的问题。我还没有找到让这条线正确的方法。但是,我发现你可以添加

    System.Diagnostics.Debugger.Break();
    

    在你要测试的那一行,然后调试T4模板。您的 IDE 仍将位于错误的行,但如果您转到代码中触发中断的位置 - 中断 应该 所在的位置 - 您至少可以在该点检查变量。

    警告:如果您尝试使用调试器行保存或运行模板,它有时会导致 Visual Studio 崩溃。不使用时立即注释掉。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-17
      • 2011-05-10
      相关资源
      最近更新 更多