I have overridden the controller generation T4 templates (ControllerWithContext.tt
) as described here.
I would like to take advantage of the code helper uti
The answer is that the template processor isn't even trying to get the include file (as confirmed using ProcMon). You can reproduce this using any template, not just the EF.Utility.CS.ttinlcude
Not sure why you need the code but you can always build your own base class, just have it inherit from Microsoft.VisualStudio.TextTemplating.TextTransformation and then put in all the code thats is in the EF.Utility file. Then set the inherits directive to point to your new base class and then you can access those methods from your template.
If you have Visual Studio 2012 or 2013, install this EF tool to resolve the error.
Following @DustinDavis' advice, and using the invaluable information found on OlegSych's site, here's what I did:
Added project references to
For this last reference I had to install the correct version of the Visual Studio SDK
<#@ import namespace="<name>" #>
to using <name>;
<#+ #>
using Microsoft.VisualStudio.TextTemplating;
Extended the class:
public class CodeGenerationTools : TextTransformation
Override the TransformText
method
public override string TransformText() {
throw new NotImplementedException();
}
Added empty constructor
public CodeGenerationTools() {
_textTransformation = DynamicTextTransformation.Create(this);
_code = new CSharpCodeProvider();
_ef = new MetadataTools(_textTransformation);
FullyQualifySystemTypes = false;
CamelCaseFields = true;
}
The next steps took place in the main project - Edited the T4 template file. - Changed template directive to
<#@ template language="C#" HostSpecific="True" debug="false" inherits="CodeGenerationTools"#>
- Added the directives
<#@ assembly name="C:\Visual Studio 2010\Projects\CodeGenerationTools\CodeGenerationTools\bin\Debug\CodeGenerationTools.dll" #>
<#@ import namespace="CodeGenerationTools" #>
All of which now means I can use the helper methods found in EF.Utility.CS.ttinclude in my own T4 templates, and I have the means to add my own helper methods which will be available to all projects.