I use ASP.NET MVC 3 Custom CodeTemplates I need to put some methods in one t4 file and then use it in all my t4 templates.
So this is my general.tt file:
<#@ template language="C#" #> <#@ assembly name="System" #> <#@ assembly name="System.Core" #> <#@ assembly name="System.ComponentModel.DataAnnotations" #> <#@ assembly name="System.Data" #> <#@ assembly name="System.Data.Entity" #> <#@ assembly name="System.Data.Linq" #> <#@ assembly name="System.Xml.Linq" #> <#@ import namespace="System" #> <#@ import namespace="System.Linq" #> <#@ import namespace="System.Text" #> <#@ import namespace="System.Collections.Generic" #> <#@ import namespace="System.ComponentModel.DataAnnotations" #> <#@ import namespace="System.ComponentModel" #> <#@ import namespace="System.Data.Linq.Mapping" #> <#@ import namespace="System.Data.Objects.DataClasses" #> <#@ import namespace="System.Reflection" #> <#@ import namespace="Microsoft.VisualStudio.Web.Mvc.Scaffolding.BuiltIn" #> <#+ public class XXD { public string getitNow(){ return "Yup thats it!"; } } #>
Then I use it in create.tt file like this:
<#@ include file="general.tt" #> ... <#+ private string GetitNow(){ XXD xx = new XXD(); return xx.getitNow(); }
but there is an error when I want to Add View Use create template:
error: Loading the included file 'general.tt' returned a null or empty string. The transformation will not be run.
So where is the problem? what is your suggestion to do this?