Visual Studio 2008 - VS 上的 T4 错误。编译转换:'Write'不是成员



我正试图在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.TextTemplateF77BDE667ECAD297F587D3D651053846。GeneratedTextTransformation.SomeClass'.D:\Development\PrivateProjects\CodeGeneration\CodeGeneration\Generation\Common\test2.tt 16 1 CodeGeneration

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

代码。。。

#>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 
#>

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

相关内容

最新更新