For ASP.NET Core 3 release version:
services.AddControllersWithViews().AddRazorRuntimeCompilation();
https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-3.0
It can also be enabled conditionally only for local development, quoted from the link:
Runtime compilation can be enabled such that it’s only available for
local development. Conditionally enabling in this manner ensures that
the published output:Uses compiled views.
Is smaller in size.
Doesn’t enable file watchers
in production.
public Startup(IConfiguration configuration, IWebHostEnvironment env)
{
Configuration = configuration;
Env = env;
}
public IWebHostEnvironment Env { get; set; }
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
IMvcBuilder builder = services.AddRazorPages();
#if DEBUG
if (Env.IsDevelopment())
{
builder.AddRazorRuntimeCompilation();
}
#endif
}