Arbitrary base classes and custom keywords

Apr 22, 2011 at 8:28 PM

[Copied from an email written by Jess Chadwick]


I love the work you've done with RazorSingleFileGenerator, but I could not use it in its current state on either of the two projects I am currently working on because we are using custom Razor keywords and base classes not derived from the Razor WebPage base class.   I recognized that your project could be easily modified to support everything I needed, so I did so.  I have two main changes:

1) I wanted to use RazorSingleFileGenerator to work with arbitrary template base classes (i.e. not Helper- or WebPage-based), so I added the "BasicHost" to support this.  It eliminates all unnecessary artifacts and is slimmed down to support the barebones Execute method.  I'm not in love with the name and am open to suggestions.  This is contained in the first two changesets and can be imported autonomously from change #2.

2) At my current client we are using an extended Engine to support our own custom keywords.  To this end, I added the ability to locate and import custom ISingleFileGenerators on the fly.  The config-file based implementation seemed simple and effective, but I'm open to alternatives.

Overall I love your project and I hope that you'll accept these changes because I really think they are quite simple - and powerful - additions to help the tool better support many different scenarios.  Please let me know what you think or if I can do anything else to help!

- Jess Chadwick

Apr 22, 2011 at 8:28 PM

[Reply by pranavkm]

I haven’t had time to run and test it, but the changes from item #1 look great.

For item 2, it would be nicer if we went the MEF route.  We’ve been using it in a couple of our projects and it works pretty well out of the box. I’ll work on the MEF changes once I get back home today evening. 

Apr 25, 2011 at 6:11 PM


Saw your MEF changes and they look great - nice and clean.

I have one comment:  you currently have the RazorHosts folder at the Project level.  Perhaps it makes more sense to include this at the solution level instead? I would assume that you'd want these same Hosts available across all projects in a solution.  (Plus, the solution level approach might help integrate them with NuGet better down the road?)  My initial commit included both the Solution and the Project level (which actually may have been overkill).


Apr 25, 2011 at 7:34 PM

It shouldn't be particularly hard to add arbitrary folders. As long as we are ok with some convention for where to look for hosts at the solution level e.g. $(SolutionDirectory)\RazorHosts we should be able to add that to MEFs search paths.



Apr 26, 2011 at 7:21 PM

I've added support for solution level RazorHosts in changeset 230ea82cf3e1 Let me know if you have any trouble using it.