This project is read-only.

How to add a custom transformer?

Sep 28, 2011 at 2:13 PM

I would like to add a custom (exported) transformer without changing/re-compiling the code in RazorGenerator.Tooling

I figured I could derive an exported transformer from one of the existing ones (e.g. MvcViewTransformer).

Question is: how to make sure RazorGenerator finds it through MEF? Registrate? How, as what?

Coordinator
Sep 28, 2011 at 4:56 PM

We look for additional assemblies under a directory named RazorHosts (we should probably rename this) under the project and a directory above the project directory which we assume to be the solution root.

e.g. if your directory sturcture looks like this:

c:\Solution\Project1\Project.csproj

We'll look for assemblies under C:\Solution\RazorHosts and C:\Solution\Project1\RazorHosts and use MEF to search for additional generators. Once you create the assembly, export it via MEF as Export("<Generator Name>", typeof(IRazorCodeTransformet)]. The generator name is what you specify as a directive in your view. If you plan on specifying the same host for all files in your app, you could specify it in a file named "razorgenerator.directives" located at project root (C:\Solution\Project1\razorgenerator.directives). Its the same name: value format that you use in your cshtml file without the razor comment blocks surrounding it.

 

 

 

 

 

Oct 3, 2011 at 12:43 PM
Edited Oct 3, 2011 at 1:38 PM

Could you be more specific. It just doesn't seem to work.

I added a project RazorHosts to the solution in directory ..\Solution\RazorHosts. I even compiled the assembly to that same directory (not bin\Debug). I restarted VS2010. But my transformer is never detected nor used.

 


    [Export("MyMvcView", typeof(IRazorCodeTransformer))]
    public class MyMvcViewTransformer : MvcViewTransformer
    {
        public override string ProcessOutput(string codeContent)
        {
            codeContent.Insert(0, "Test test");
            return base.ProcessOutput(codeContent);
        }
    }
Update: loadExtensions seems always false !!
Coordinator
Oct 3, 2011 at 5:13 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.