Calvin Pang
Calvin Pang

Reputation: 21

How to get Reuseable ViewComponent in class library (Dotnet core 3.0)

In Dotnet Core 2.1 in am using below code to get the viewComponent from class library.

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();

    var assembly = typeof(ViewComponentLibrary.ViewComponents.SimpleViewComponent).GetTypeInfo().Assembly;

    //Create an EmbeddedFileProvider for that assembly
    var embeddedFileProvider = new EmbeddedFileProvider(
        assembly,
        "ViewComponentLibrary"
    );

    //Add the file provider to the Razor view engine
    services.Configure<RazorViewEngineOptions>(options =>
    {                
        options.FileProviders.Add(embeddedFileProvider);
    });
}

But in Dotnet Core 3.0 , i could not found the File Provider in RazorViewEngineOptions. Could some one advise how to get the viewComponent or .cshtml from class library ? Thanks

Upvotes: 1

Views: 1087

Answers (1)

Calvin Pang
Calvin Pang

Reputation: 21

https://github.com/aspnet/AspNetCore/issues/14374

AddRazorRuntimeCompilation() and change the library class to Razor class library

Upvotes: 1

Related Questions