Skip to content

[Breaking change]: Razor runtime compilation is obsolete #522

@BrennanConroy

Description

@BrennanConroy

Description

Razor runtime compilation is obsolete and is not recommended for production scenarios. For production scenarios, use the default build time compilation. For development scenarios, use Hot Reload instead.

Version

.NET 10 Preview 7

Previous behavior

Developers could use Razor runtime compilation to recompile .cshtml files while the application is running. This is useful for development time so you don't need to restart the application for changes to take affect.

We're now obsoleting this and recommending developers make use of Hot Reload which has the same effect for development time.

New behavior

Using the APIs listed below will produce a compiler warning with diagnostic ID ASPDEPR003:

warning ASPDEPR003: Razor runtime compilation is obsolete and is not recommended for production scenarios. For production scenarios, use the default build time compilation. For development scenarios, use Hot Reload instead. For more information, visit https://aka.ms/aspnet/deprecate/003.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
  • Behavioral change: Existing binaries may behave differently at run time.

Reason for change

Razor Runtime compilation has been replaced by Hot Reload which has been the recommended approach for a few years now. We're making it clearer that Razor Runtime compilation is not getting support for new features and should no longer be used.

Recommended action

Remove calls to .AddRazorRuntimeCompilation() and use Hot Reload.

Affected APIs

Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPartExtensions
Microsoft.Extensions.DependencyInjection.RazorRuntimeCompilationMvcBuilderExtensions.AddRazorRuntimeCompilation
Microsoft.Extensions.DependencyInjection.RazorRuntimeCompilationMvcCoreBuilderExtensions.AddRazorRuntimeCompilation
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.FileProviderRazorProjectItem
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.MvcRazorRuntimeCompilationOptions

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking changeDocumentedThe breaking change has been published to the .NET Core docs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions