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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With