Header add

In this article we will learn about ASP.NET Core 5 – Enabling Razor runtime compilation.

Recently I have created a Razor file project I facing razor runtime compilation issue. Razor files (.cshtml) are compiled at both build and publish time and this gives better performance as your views are compiled.
We can also enable runtime compilation, which will help developers to see any modified view change in real-time, without starting the application again. 

The recent version of ASP.NET Core (ASP.NET Core 6.0). But I have tested it on .NET 5. ASP.NET Core 5.0 changes this experience for enabling razor runtime compilation. This is now available as an option while creating the ASP.NET Core 5.0 project.


To enable Razor runtime compilation in ASP.NET Core 5.0

With ASP.NET Core 5, to enable razor file compilation, there is no need to explicitly add Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package. When you create a new project targeted to ASP.NET Core 5, You can enable this feature like below.

ASP.NET-Core-5-support-for-Enabling-Razor-runtime-compilation

With ASP.NET core 5.0, this is handled via launchsetting.json file. You will see the following content in the launchsetting.json file. To disable this on the development environment, comment or remove the line 16 and 25.




While creating the project, if you forgot to check the “Enable Razor runtime compilation” option, then you can still enable it via adding the nuget package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation and then configuring in the Startup.cs.


Summary
In this tutorial we discussed ASP.NET Core 5 – Enabling Razor runtime compilation. If have any question related to this topic then give your feedback.

Post a Comment

Previous Post Next Post