Well, I managed to get the necessary link to the @FuleSnabel assembly, gave me a hint, although I did not use his suggestion.
Here is part of my T4 template:
<#@ template debug="true" hostSpecific="true" #> <#@ output extension=".output" #> <#@ Assembly Name="System.Core.dll" #> <#@ Assembly Name="System.Windows.Forms.dll" #> <#@ Assembly Name="System.Xml.Linq.dll" #> <#@ Assembly Name="Microsoft.VisualStudio.Shell.Interop.8.0" #> <#@ Assembly Name="EnvDTE" #> <#@ Assembly Name="EnvDTE80" #> <#@ Assembly Name="VSLangProj" #> <#@ import namespace="System" #> <#@ import namespace="System.IO" #> <#@ import namespace="System.Diagnostics" #> <#@ import namespace="System.Linq" #> <#@ import namespace="System.Xml.Linq" #> <#@ import namespace="System.Collections" #> <#@ import namespace="System.Reflection" #> <#@ import namespace="System.Collections.Generic" #> <#@ import namespace="Microsoft.VisualStudio.TextTemplating" #> <#@ import namespace="Microsoft.VisualStudio.Shell.Interop" #> <#@ import namespace="EnvDTE" #> <#@ import namespace="EnvDTE80" #> <#@ include file="T4Toolbox.tt" #> <# Project prj = GetProject(); string fileName = "$(ProjectDir)bin\\debug\\" + prj.Properties.Item("OutputFileName").Value; string path = Host.ResolveAssemblyReference(fileName); Assembly asm = Assembly.LoadFrom(path); // .... #> // generated code goes here <#+ Project GetProject() { var serviceProvider = Host as IServiceProvider; if (serviceProvider == null) { throw new Exception("Visual Studio host not found!"); } DTE dte = serviceProvider.GetService(typeof(SDTE)) as DTE; if (dte == null) { throw new Exception("Visual Studio host not found!"); } ProjectItem projectItem = dte.Solution.FindProjectItem(Host.TemplateFile); if (projectItem.Document == null) { projectItem.Open(Constants.vsViewKindCode); } return projectItem.ContainingProject; } #>
So, in order to find the correct path to the assembly, I had to get the project link in the GetProject() method, and then use the project property OutputFileName with prj.Properties.Item("OutputFileName").Value . Since I could not find anywhere that the properties project had, I used an enumeration and a loop to check the Properties collection, and then found what I needed. Here is the loop code:
<# // .... foreach(Property prop in prj.Properties) { #> <#= prop.Name #> <# } // .... #>
Hope this helps someone.
source share