Razor Class Library and Umbraco with runtime compilation

Might be a little late to the party but when reading this i remembered a proof of concept that I worked on in the beginning of this year.

Basically allowing for “feature folders” that looks like this:

I didn’t finish this but i did get the views runtime compilation to work outside the Views folder in a RCL by adding a PhysicalFileProvider to the options during startup:

public static class StartupExtensions
{

    public static WebApplicationBuilder AddRazorRuntimeCompilation(this WebApplicationBuilder builder)
    {
        builder.Services
            .AddControllersWithViews()
            .AddRazorRuntimeCompilation();

        builder.Services.Configure<MvcRazorRuntimeCompilationOptions>(options =>
        {
            // This is the physical path to the project root, same as "../UmbProject.Web"
            var libraryPath = Path.GetFullPath(Path.Combine(builder.Environment.ContentRootPath, "..", "UmbProject.Web"));
            options.FileProviders.Add(new PhysicalFileProvider(libraryPath));
        });

        return builder;
        
    }
}

Just exactly right now, the POC is not in a “sharable” state but if this does not help you I could try to find some time to publish something to Github.

Edit:
Oh, one thing that I forgot to mention. I have a RenderController for each Document Type that returns the part to the view. Similar to this:

public class CmsArticle2Controller : RenderController
{
    ....

    public override IActionResult Index()
    {
        var viewModel = BuildViewModel(this.CurrentPage);

        return View("Pages/Article/Article.cshtml",viewModel);

    }
}

All this is inside the RCL.
1 Like