I have a Razor Class Library which contains some razor views, and some content within its wwwroot folder.
When I import the compiled DLL file into a .NET Core web project using Visual Studio (Add Project Reference), all works well.
However, if I attempt to load the DLL dynamically (using reflection), all seems to work apart from being able to access the content within the wwwroot folder (i.e., its not mapped to the _content/AssemblyName/ path).
I'm using the following code to import the assembly dynamically and add it as an application part:
Assembly PrimaryAssembly = Assembly.LoadFrom("bin\\Debug\\net6.0\\RCL.dll");
AssemblyPart assemblypart = new AssemblyPart(PrimaryAssembly);
EmbeddedFileProvider fileProvider = new EmbeddedFileProvider(PrimaryAssembly);
services.AddControllersWithViews().ConfigureApplicationPartManager(apm => apm.ApplicationParts.Add(assemblypart));
services.Configure<MvcRazorRuntimeCompilationOptions>(options => options.FileProviders.Add(fileProvider));
I'm using .NET Core 6.0.
Any Ideas?
Cheers.
I managed to get a solution to this problem with some help from @ZhiLv-MSFT over on the Microsoft Q&A forums.
This article explained all: https://www.codeproject.com/Articles/5296270/ASP-NET-Core-3-x-Dynamically-Loadable-Plugins-with
The contents of the CodeProject article solved it for me.
The important piece was creating the ManifestEmbeddedFileProvider (which pointed to the Assembly, and the location that the files where (in my case "wwwroot")), then appending this file provider onto the rest using a CompositeFileProvider.
That all seems to work brilliantly.