Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It's possible to editing Razor page (.cshtml) in Razor Class Library during debugging without restart? VS 2017

I have an ASP.Net MVC Core application that references the Razor class library that has SomePage.cshtml.

When debugging the application, I can edit pages in the application ASP.Net MVC Core, and the changes are reflected in the browser (after refreshing).

But when I edit pages in the Razor Class Library, the changes are not visible in the browser (after refreshing). I need to stop the application and restart - then the changes will be visible in the browser.

Is there any way to refresh edited pages in the Razor Class Library without restarting?

like image 795
Mike Dev Avatar asked Aug 13 '19 11:08

Mike Dev


2 Answers

That's not possible. In .NET all class libraries must be compiled before executing the code and the compiled reference is included in the original project. So any changes to the class libraries must be compiled again.so we need stop project to compile code and update refrence.

like image 183
masoud Avatar answered Oct 19 '22 22:10

masoud


It's possible after installing Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package.

Then configure:

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

    services.Configure<MvcRazorRuntimeCompilationOptions>(options =>
    {
        var libraryPath = Path.GetFullPath(
            Path.Combine(HostEnvironment.ContentRootPath, "..", "MyClassLib"));
        options.FileProviders.Add(new PhysicalFileProvider(libraryPath));
    });
}

More details here

like image 32
Jan Muncinsky Avatar answered Oct 19 '22 23:10

Jan Muncinsky