|
| 1 | +--- |
| 2 | +title: "Breaking change: Razor runtime compilation is obsolete" |
| 3 | +description: Learn about the breaking change in ASP.NET Core 10.0 where Razor runtime compilation APIs have been marked obsolete. |
| 4 | +ms.date: 08/08/2025 |
| 5 | +--- |
| 6 | + |
| 7 | +# Razor runtime compilation is obsolete |
| 8 | + |
| 9 | +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. |
| 10 | + |
| 11 | +## Version introduced |
| 12 | + |
| 13 | +.NET 10 Preview 7 |
| 14 | + |
| 15 | +## Previous behavior |
| 16 | + |
| 17 | +Developers could use [Razor runtime compilation](/aspnet/core/mvc/views/view-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 effect. |
| 18 | + |
| 19 | +## New behavior |
| 20 | + |
| 21 | +Using the APIs listed below will produce a compiler warning with diagnostic ID `ASPDEPR003`: |
| 22 | + |
| 23 | +> 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>. |
| 24 | +
|
| 25 | +## Type of breaking change |
| 26 | + |
| 27 | +This change affects [source compatibility](../../categories.md#source-compatibility). |
| 28 | + |
| 29 | +## Reason for change |
| 30 | + |
| 31 | +Razor Runtime compilation has been replaced by Hot Reload which has been the recommended approach for a few years now. This change makes it clearer that Razor Runtime compilation is not getting support for new features and should no longer be used. |
| 32 | + |
| 33 | +## Recommended action |
| 34 | + |
| 35 | +Remove calls to `.AddRazorRuntimeCompilation()` and use Hot Reload. |
| 36 | + |
| 37 | +### Before |
| 38 | + |
| 39 | +```csharp |
| 40 | +public void ConfigureServices(IServiceCollection services) |
| 41 | +{ |
| 42 | + services.AddMvc() |
| 43 | + .AddRazorRuntimeCompilation(); |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +### After |
| 48 | + |
| 49 | +Remove the call to `AddRazorRuntimeCompilation()`: |
| 50 | + |
| 51 | +```csharp |
| 52 | +public void ConfigureServices(IServiceCollection services) |
| 53 | +{ |
| 54 | + services.AddMvc(); |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +For development scenarios, use [Hot Reload](/dotnet/core/tools/dotnet-watch) instead: |
| 59 | + |
| 60 | +```console |
| 61 | +dotnet watch |
| 62 | +``` |
| 63 | + |
| 64 | +## Affected APIs |
| 65 | + |
| 66 | +- <xref:Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPartExtensions?displayProperty=fullName> |
| 67 | +- <xref:Microsoft.Extensions.DependencyInjection.RazorRuntimeCompilationMvcBuilderExtensions.AddRazorRuntimeCompilation%2A?displayProperty=fullName> |
| 68 | +- <xref:Microsoft.Extensions.DependencyInjection.RazorRuntimeCompilationMvcCoreBuilderExtensions.AddRazorRuntimeCompilation%2A?displayProperty=fullName> |
| 69 | +- <xref:Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.FileProviderRazorProjectItem?displayProperty=fullName> |
| 70 | +- <xref:Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.MvcRazorRuntimeCompilationOptions?displayProperty=fullName> |
0 commit comments