【问题标题】:T4 error on VS. Compiling transformation: 'Write' is not a memberVS 上的 T4 错误。编译转换:'Write' 不是成员
【发布时间】:2008-10-17 14:15:09
【问题描述】:

我正在尝试在 VS2008 的 T4 模板中使用一个类。

这是我正在做的简化版本...

<#@ template language="VB" debug="True" hostspecific="True" #>
<#@ output extension=".vb" debug="True" hostspecific="True" #>
<#@ assembly name="System.Data" #>
<#@ assembly name="System.Windows.Forms.dll" #>
<#@ assembly name="System.xml" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Data.SQLClient" #>
<# Call (New SomeClass).Start()#>
<#+
Private Class SomeClass
    Public Sub Start()
    #>test<#+
    End Sub
End Class 
#>

当我运行此模板时...我收到以下错误...


错误 1 ​​编译转换:'Write' 不是 'Microsoft.VisualStudio.TextTemplatingF77BDE667ECAD297F587D3D651053846。 GeneratedTextTransformation.SomeClass'。 D:\Development\PrivateProjects\CodeGeneration\CodeGeneration\Generation\Common\test2.tt 16 1 CodeGeneration

谁能告诉我为什么这会导致错误,更重要的是如何消除它的影响?

【问题讨论】:

    标签: visual-studio-2008 t4


    【解决方案1】:

    代码...

    #>test<#+
    

    ...内部转换为...

    Write("test"); 
    

    由于我的类没有“Write”方法,因此编译失败。

    解决方法是......

    <#@ template language="VB" debug="True" hostspecific="True" #>
    <#@ output extension=".vb" debug="True" hostspecific="True" #>
    <#@ assembly name="System.Data" #>
    <#@ assembly name="System.Windows.Forms.dll" #>
    <#@ assembly name="System.xml" #>
    <#@ import namespace="System.Collections.Generic" #>
    <#@ import namespace="System.Data.SQLClient" #>
    <#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
    
    <# Call (New SomeClass(Me)).Start()#>
    
    <#+
    Private Class SomeClass
    Private mOutput as TextTransformation
    Public Sub New(Output as TextTransformation)
        mOutput = Output
    End Sub 
    Public Sub Write(SomeText as String)
        mOutput.Write(SomeText)
    End Sub 
        Public Sub Start()
            #>test<#+
        End Sub
    End Class 
    #>
    

    这会导致将写入传递给父类进行处理。

    【讨论】:

      猜你喜欢
      • 2012-08-31
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多