Thursday, July 2, 2020

Razor compilation

In .NET Core (3.x) Razor compilation happens by default at build time. This means that every time you make a change to a Razor file, you have to rebuild your application before a change becomes visible inside your frontend. This is different compared to .NET where Razor compilation happened at runtime.

If you have to work a lot inside Razor, build time compilation can be annoying and slow down your development process. Luckily it is possible to enable runtime compilation for your ASP.NET Core Web application.

One option you have is to enable runtime compilation at project creation:

  • Create a new ASP.NET Core Web application in Visual Studio
  • Check the Enable Razor runtime compilation check box when creating your project.

If you have an existing project, you have to take a different approach: