Home > Software engineering >  Rendering Views from external assemblies in .NET 6 web app
Rendering Views from external assemblies in .NET 6 web app

Time:05-05

I have a .NET 6 MVC Web App that references an assembly with a controller and view. I have been able to Google my way through adding reference to and calling the external controller.

Now I am stuck trying to reference the View in the assembly, as the Razor engine still expects it to exist in the main application. I saw an example for MVC6 that says to add:

builder.Services.Configure<RazorViewEngineOptions>(options =>
{
  options.FileProvider = new CompositeFileProvider(
    new EmbeddedFileProvider(
        typeof(BooksController).GetTypeInfo().Assembly,
        "BookStore.Portal" // your external assembly's base namespace
    ),
    options.FileProvider
  );
});

but 'FileProvider' is not an available property of options. Am I missing a package? Is there a better way to go about this?

Thanks.

CodePudding user response:

So at least for .NET 6 you don't have to do anything special. Just reference your Razor Class Library and you have access to it. Nothing in the Startup (now Program). I did have to structure the project in the typical 'Controllers'/'Views' folder structure, but my calling application finds the controllers and views.

  • Related