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

ASR 671 Reputation points
2022-02-06T07:36:07.047+00:00

Hi,

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.

https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-5.0&tabs=visual-studio#enable-runtime-compilation-in-an-existing-project

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,242 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,131 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 57,966 Reputation points
    2022-02-06T16:43:56.89+00:00

    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: Most helpful
  1. Sreeju Nair 11,856 Reputation points
    2022-02-06T08:08:06.307+00:00

    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