I can't get Razor Runtime Compilation to work with a dynamically loaded assembly. My code:
Startup.cs
var assembly = Assembly.LoadFrom(someModuleDllPath);
var viewsAssembly = Assembly.LoadFrom(someModuleViewsDllPath);
services.AddControllersWithViews()
.AddApplicationPart(assembly)
.AddApplicationPart(viewsAssembly)
.AddRazorRuntimeCompilation();
services.Configure<MvcRazorRuntimeCompilationOptions>(options => {
options.FileProviders.Add(new EmbeddedFileProvider(assembly));
});
With this approach, I need to rebuild the loaded assembly project and restart the host to see changes. When I replace the last two lines with:
services.Configure<MvcRazorRuntimeCompilationOptions>(options => {
options.FileProviders.Add(new PhysicalFileProvider(loadedAssemblyProjectContentRootPath));
});
I get the error:
Cannot find compilation library location for package '<name of loaded assembly>'.
Setting MvcRazorExcludeRefAssembliesFromPublish
to false
doesn't change anything. The option with PhysicalFileProvider
works when I add an explicit reference to the project.
I'm using .NET 5 and both projects have the Microsoft.NET.Sdk.Web
type.
Is there any way I can make it work?