Why run time compilation is not available by default in .NET Core.

Amit Rawat 586 Reputation points


View content doesn't render automatically when I modify static content of view page in .NET 5. For that I need to download "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" package from Nuget and then apply services.AddControllersWithViews().AddRazorRuntimeCompilation(); within my startup.cs class.

My question is why it is not available by default. Is there any specific reason or it is just to save few MB from default installation.

Below documentations only says it is optionally enable. Nothing specific. Is there any disadvantages of using it.


A set of technologies in the .NET Framework for building web applications and XML web services.
3,137 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: The period of time during which a program is being executed in a computer.
996 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 35,791 Reputation points

    There are a couple reasons. The one is the project size, but the other is security. Microsoft learned the hard way that the larger the default code base, the more likely an exploit will be found. On the surface, allowing on site recompilation seems less secure.

    As the current trend is CI/CD this feature is not commonly required.

    0 comments No comments

1 additional answer

Sort by: Oldest
  1. sreejukg 10,461 Reputation points

    You can enable runtime compilation with ASP.Net core. By default, Razor SDK will do build-time and publish-time compilation. When you enable runtime compilation, it helps you to update Razor files after the site is published.

    refer: https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-6.0&tabs=visual-studio

    Hope this helps

    0 comments No comments