Since ASP.Net Core version 3.0 and higher:
A) Editing a Razor View (.cshtml) file while running the application does not apply the changes until restart.
B) Looks like edit and continue is not working.
IDE and Version: Microsoft Visual Studio 2019
Since ASP.Net Core version 3.0 and higher:
A) Editing a Razor View (.cshtml) file while running the application does not apply the changes until restart.
B) Looks like edit and continue is not working.
IDE and Version: Microsoft Visual Studio 2019
For this issue, I suggest you try to install package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation and then configure AddRazorRuntimeCompilation in Startup.cs like
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews().AddRazorRuntimeCompilation();
}
For this issue, you could trace by Breaking changes to runtime compilation for Razor views and Razor Pages #343
Please use NuGet package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation Version 3.1.7 that is compatible with ASP.Net Core 3.1 and apply following line of code in Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddControllersWithViews().AddRazorRuntimeCompilation();
}
Note as indicated in the "Razor file compilation in ASP.NET Core" posted by Givi, if you just want this feature for rapid development, you can enable this just for development and not for production by NOT adding
.AddRazorRuntimeCompilation()
to Startup.cs, and instead adding these environment variables to your launchSettings.json
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
"ASPNETCORE_ENVIRONMENT" = "Development"
only for our integrated development environment (Dev appserver deployed through DevOps) and use
"ASPNETCORE_ENVIRONMENT" = "Local"
for individual developer's local development (in an accompanying appsettings.Local.json config file).
I'm happy to report that "ASPNETCORE_ENVIRONMENT" does not strictly need to be set to "Development" and that runtime compilation works for "Local" (and presumably whatever is the name you use for the environment you develop under).
But one thing I found was that although I added ASPNETCORE_HOSTINGSTARTUPASSEMBLIES to launchSettings.json, it was being removed (and thus not working) by the project properties Debug tab until I added the variable there (and now it works great).
I was working on an asp.net core 3.1 project that was somehow modular and each module had their own Controller & Views. Modules where living in a folder in solution root folder. In such a case only adding AddRazorRuntimeCompilation method didn't helped me and I had to configure FileProviders. Just wanted to note the right configuration for me was to add every modules folder path, actually folder that contains .csproj file in it, to FileProviders for some one like me wasting a lot of time to configure.