I had a similar issue with using CompiledRazorAssemblyPart
, and it turns out the problem was that I was adding my RCL assembly (e.g. MyPlugin.dll) as a CompiledRazorAssemblyPart
, whereas you need to add the .Views assembly (e.g. MyPlugin.Views.dll). Below is an example of the code I'm now using to add a plugin assembly that is not referenced by the main web application project. Note that you probably still want the plugin assembly as a standard application part for controllers etc.
public static void AddPluginApplicationPart(IMvcBuilder mvcBuilder, Assembly assembly)
{
mvcBuilder.AddApplicationPart(assembly);
Assembly viewsAssembly = null;
try
{
viewsAssembly = Assembly.Load(assembly.GetName().Name + ".Views");
}
catch (FileNotFoundException)
{
}
if (viewsAssembly != null)
{
// Adding this application part allows us to use compiled razor views from this plugin
var viewsApplicationPart = new CompiledRazorAssemblyPart(viewsAssembly);
mvcBuilder.ConfigureApplicationPartManager(manager => manager.ApplicationParts.Add(viewsApplicationPart));
}
}