I've got a T4 template with a line like this:
Dim Variables = (From line in file.EnumerateLines() _
Let data = line.Split("|".ToCharArray())
Select new Variable With {.Name = data(0), .Type = data(1)}).ToList()
Variable
is defined elsewhere in the file, and EnumerateLines
is defined in a utility library referenced by the template. But I get tons of T4 compiler errors like Close_parens expected
even though this is valid code that I cut and pasted from a VB code file in the IDE where it compiled just fine. I'm referencing all needed libraries and importing namespaces, but it seems like T4 will only accept VB code from 8 years ago. For example, this code is functionally identical, and compiles:
Dim Variables As New List(Of Variable)
for each lineX As String in EnumerateLines(file)
Dim data = lineX.Split("|".ToCharArray)
Dim v as New Variable
v.Name = data(0)
v.Type = data(1)
Variables.Add(v)
next
How do I get T4 to understand LINQ, extension methods, initializers, and all the other stuff it doesn't seem to understand?
Update: Just to clarify, I have the needed assemblies and namespaces imported:
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="Microsoft.VisualBasic" #>