Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AspNet Core 3.0 and 3.1 : Enable runtime compilation for Razor Pages

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

like image 500
sajid Avatar asked Sep 30 '19 19:09

sajid


People also ask

How do I enable Razor runtime compilation?

Enable runtime compilation at project creationIn the Create a new ASP.NET Core web application dialog: Select either the Web Application or the Web Application (Model-View-Controller) project template. Select the Enable Razor runtime compilation checkbox.

Does ASP.NET Core use Razor pages?

Razor Pages is the default for building server-side web applications in ASP.NET Core. Components within the underlying MVC framework still have their uses such as using controllers for building RESTful APIs.

How do I run a Razor page in Visual Studio code?

Open project in VS Code Shut down your application using Ctrl+C . Open your project in VS Code using one of the following options: Select File > Open Folder, and then select the RazorPagesMovie folder. Enter the following command in the terminal code .


2 Answers

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();    
    }
like image 35
Amit Kumar Shrivastava Avatar answered Sep 27 '22 21:09

Amit Kumar Shrivastava


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

like image 157
Edward Avatar answered Sep 27 '22 19:09

Edward