Preprocessed Text Templates and Generators

Jun 30, 2010 at 1:55 PM

Hello,

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="T4Toolbox.tt" #>.
  Source=T4Toolbox.10.0
  StackTrace:
       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);
generator.Run();

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 T4Toolbox.tt 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 ?

Matthieu

 

 

 

Coordinator
Jul 13, 2010 at 12:05 PM

Matthieu,

Where can I see the source code of your extension?

Oleg

Jul 16, 2010 at 7:43 PM

Hello Oleg,

 

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

 

Matthieu

Aug 23, 2011 at 4: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="T4Toolbox.tt" #>.   
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\GenMVVM.tt:line 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();   
gen.Run();

 

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

 

Sep 6, 2011 at 3:24 PM

Working perfectly misunderstand from me.