I'm designing a plugin framework for ASP.NET MVC3 using Razor views, and I'm having an issue getting the embedded views to work correctly.
The plugin framework is designed to have these features:
- Each plugin has its own models, controllers and views. The views are embedded resources, and the controllers derive from a PluginController class
- The plugins have dependency references to a shared class library that defines the PluginController base class
- The "shell" web application that hosts the plugins must not hold references to any plugins at design time, since it does not know at design time which plugins it has.
- The plugin dll's are dropped in a folder in the shell application, which is not the /bin folder
- The shell takes care of:
- Discovering the plugins (using reflection)
- Registering all controllers (I'm using Spring.Net for this)
- Creating routes to the controllers
- Serving the razor files (cshtml) through a custom VirtualPathProvider
Now everything works fine, except when the embedded views have references to types within the plugin dll. Then I get the infamous error (names left out):
The type or namespace name '[Plugins]' does not exist in the namespace '[MyPluginSolution]' (are you missing an assembly reference?)
The reason for this is that the csc compiler which is invoked runtime to compile the razor views only get the dll references from the bin folder and the GAC.
I've also tried pre-compiling the views using this technique but in the end it gives the same results, since the runtime insists on compiling a wrapper for the pre-compiled razor view.
I could of course drop the plugin dll in the /bin folder, but my question is:
Is there a way to register dlls in a non-bin (and non-GAC) folder, and treat them as "first class citizens" so they can be used by the razor views?