This project is read-only.

Preprocessed Text Templates and Generators

Jun 30, 2010 at 2:55 PM


I have a Feature Extension to add some commands in Visual Studio and it's deployed as a vsix file. Inside one of my command I would like to run a generator.

I have migrated my existing templates to be Preprocessed ones and the existing generators are now "simple" classes which inherits from Generator.

When I try to run a generator I got this exception : 

Message=Transformation context was not properly initialized. Please make sure your template uses the following directive: <#@ include file="" #>.
       at T4Toolbox.TransformationContext.get_Transformation()
       at T4Toolbox.TransformationContext.get_HostProperty()
       at T4Toolbox.TransformationContext.get_Host()
       at T4Toolbox.TransformationContext.Render(String content, OutputInfo output, CompilerErrorCollection errors)
       at T4Toolbox.Template.Render()
       at Templates.PackageGenerator.RunCore() in PackageGenerator.cs:line 31
       at T4Toolbox.Generator.Run()

and the code : 

var generator = new PackageGenerator(package);

I know that there's more than generator and template, there's an engine, a host but I can't figure out how to get them. I'm already in the DTE, Visual Studio etc... context because I already have some code manipulating the Solution (and my code is inside a Feature Extension). I see in the file two directives :

<#@ dte processor="T4Toolbox.DteProcessor" #>
<#@ TransformationContext processor="T4Toolbox.TransformationContextProcessor" #>

Somehow before calling my generator I should have done what this two directives does ?





Jul 13, 2010 at 1:05 PM


Where can I see the source code of your extension?


Jul 16, 2010 at 8:43 PM

Hello Oleg,


Thanks for helping me out but we just switch to another solution to generate the files (through CodeDom).



Aug 23, 2011 at 5:01 PM

I Have kind of same errors.

Error 13
Running transformation: T4Toolbox.TransformationException: Transformation context was not properly initialized. 
Please make sure your template uses the following directive: <#@ include file="" #>.   
at T4Toolbox.TransformationContext.get_Transformation()   
        at T4Toolbox.TransformationContext.get_HostProperty()   
                at T4Toolbox.TransformationContext.ReportErrors(CompilerErrorCollection errors)   
                at T4Toolbox.Generator.Run()   
  at Microsoft.VisualStudio.TextTemplating01691350122419378F7248B850340664.GeneratedTextTransformation.TransformText() in c:\......\Template\ 18   

at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result) 

This is the code for that line 18


var gen = new Generator1();   


All my template file including <#@ include file="" #>


Sep 6, 2011 at 4:24 PM

Working perfectly misunderstand from me.