T4 Template Project Errors
Hello
For the first time i created a t4 template, the template works fine, but after saving and generating the final file correctly it raises a lot of errors in the project, errors like the buttons aren't members of the forms, controls aren't members of the forms... and so on.
If the template fails, the errors disappear... :sick:
The template it's a simple template that generates a Enum based on values from one table in the database.
Here's the template:
vb Code:
<#@ template debug="false" hostspecific="true" language="VB" #>
<#@ output extension=".vb" #>
<#@ Assembly Name="EnvDTE.dll" #>
<#@ Assembly Name="System.Data" #>
<#@ import namespace="EnvDTE" #>
<#
Dim pathFinal As String = System.IO.Path.GetDirectoryName(Host.TemplateFile)
Dim enumName As String = "TableNames" 'Path.GetFileNameWithoutExtension(Host.TemplateFile)
Dim tableName As String = "MyTableName"
Dim columnId As String = "idMyTable"
Dim columnName As String = "Name"
Dim connectionString As String = "..."
'Get containing project
Dim serviceProvider As IServiceProvider = DirectCast(Host, IServiceProvider)
Dim dte As EnvDTE.DTE = DirectCast(serviceProvider.GetService(GetType(EnvDTE.DTE)), EnvDTE.DTE)
Dim project As Project = dte.Solution.FindProjectItem(Host.TemplateFile).ContainingProject
#>
Imports System
Imports System.CodeDom.Compiler
NameSpace <#= project.Properties.Item("DefaultNamespace").Value #><#= System.IO.Path.GetDirectoryName(Host.TemplateFile).Remove(0, System.IO.Path.GetDirectoryName(project.FileName).Length).Replace("\", ".") #>
''' <summary>
''' <#= enumName #> auto generateed
''' </summary>
Public Enum <#= enumName #>
<#
Dim con as new System.Data.SqlClient.SqlConnection(connectionString)
Dim com as new System.Data.SqlClient.SqlCommand(string.Format("SELECT {0},{1} FROM {2} ORDER BY {0}",columnId,columnName,tableName),con)
con.Open
Dim rd as System.Data.SqlClient.SqlDataReader = com.ExecuteReader()
While rd.Read
#>
<#= rd(columnName).ToString.Replace("/","").Replace(" ","") #> = <#= rd(columnId) #>
<#
End While
#>
End Enum
End Namespace
I don't understand why this happens, i removed some of the imports and put the full path in the types, just for testing...
Thanks