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));
});
}
You can edit .chtml files without stopping the solution. just need to refresh the page after our correction. if you are using visual studio, c# code too can be edited by changing the settings. press shift+f5 for hard refresh
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.