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

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:
  1. <#@ template debug="false" hostspecific="true" language="VB" #>
  2. <#@ output extension=".vb" #>
  3. <#@ Assembly Name="EnvDTE.dll" #>
  4. <#@ Assembly Name="System.Data" #>
  5. <#@ import namespace="EnvDTE" #>
  6. <#
  7.     Dim pathFinal As String = System.IO.Path.GetDirectoryName(Host.TemplateFile)
  8.     Dim enumName As String = "TableNames" 'Path.GetFileNameWithoutExtension(Host.TemplateFile)
  9.     Dim tableName As String = "MyTableName"
  10.     Dim columnId As String = "idMyTable"
  11.     Dim columnName As String = "Name"
  12.     Dim connectionString As String = "..."
  13.  
  14.     'Get containing project
  15.     Dim serviceProvider As IServiceProvider = DirectCast(Host, IServiceProvider)
  16.     Dim dte As EnvDTE.DTE = DirectCast(serviceProvider.GetService(GetType(EnvDTE.DTE)), EnvDTE.DTE)
  17.     Dim project As Project = dte.Solution.FindProjectItem(Host.TemplateFile).ContainingProject
  18.    
  19. #>
  20. Imports System
  21. Imports System.CodeDom.Compiler
  22.  
  23. NameSpace <#= project.Properties.Item("DefaultNamespace").Value #><#= System.IO.Path.GetDirectoryName(Host.TemplateFile).Remove(0, System.IO.Path.GetDirectoryName(project.FileName).Length).Replace("\", ".") #>
  24.  
  25. ''' <summary>
  26. ''' <#= enumName #> auto generateed
  27. ''' </summary>
  28. Public Enum <#= enumName #>
  29. <#
  30.     Dim con as new System.Data.SqlClient.SqlConnection(connectionString)
  31.     Dim com as new System.Data.SqlClient.SqlCommand(string.Format("SELECT {0},{1} FROM {2} ORDER BY {0}",columnId,columnName,tableName),con)
  32.     con.Open
  33.     Dim rd as System.Data.SqlClient.SqlDataReader = com.ExecuteReader()
  34.     While rd.Read
  35. #>
  36.     <#= rd(columnName).ToString.Replace("/","").Replace(" ","") #> = <#= rd(columnId) #>
  37. <# 
  38.     End While
  39. #>
  40. End Enum
  41. 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