.NET Core 3.0: Razor views don't automatically recompile on change

OK it looks like it's not supported yet :(

Runtime compilation removed As a consequence of cleaning up the ASP.NET Core shared framework to not depend on Roslyn, support for runtime compilation of pages and views has also been removed in this preview release. Instead compilation of pages and views is performed at build time. In a future preview update we will provide a NuGet packages for optionally enabling runtime compilation support in an app.

You can read more about the issue here https://github.com/aspnet/Announcements/issues/343

Applications that require runtime compilation or re-compilation of Razor files should:

  • Add a reference to the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package. It'll be available as part of the 3.0.0-preview3 release.
  • Update the application's ConfigureServices to include a call to AddMvcRazorRuntimeCompilation:

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
    }

To get runtime view compilation back in ASP.NET Core 3

  1. Reference Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
  2. Call services.AddMvc().AddRazorRuntimeCompilation()
  3. Remove Microsoft.VisualStudio.Web.CodeGeneration.Design if there's a version mismatch on the Microsoft.CodeAnalysis.Common package