1.6 KiB
1.6 KiB
title | author | description | keywords | ms.author | manager | ms.date | ms.topic | ms.assetid | ms.technology | ms.prod | uid |
---|---|---|---|---|---|---|---|---|---|---|---|
Razor view compilation and precompilation | rick-anderson | View compilation and precompilation in ASP.NET Core | ASP.NET Core,Razor view compilation, Razor pre-compilation, Razor precompilation | riande | wpickett | 5/24/2017 | article | ab4705b7-1638-1638-bc97-ea7f292fe92a | aspnet | asp.net-core | mvc/views/view-compilation |
Razor view compilation and precompilation in ASP.NET Core
Razor views are compiled at runtime when the view is invoked. ASP.NET Core 1.1.0 and higher can optionally compile Razor views and deploy them with the app (precompilation). The ASP.NET Core 2.x project templates enable precompilation.
Precompilation considerations:
- Precompiling views results in a smaller published bundle and faster startup time.
- You can't edit Razor files after you precompile views. The edited views won't be present in the published bundle.
To deploy precompiled views:
ASP.NET Core 1.x
Set MvcRazorCompileOnPublish
to true and include a package reference to Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
. The following .csproj sample highlights these settings:
[!code-xmlMain]
ASP.NET Core 2.0
Set MvcRazorCompileOnPublish
to true. The following .csproj sample highlights this setting:
[!code-xmlMain]
All the ASP.NET Core 2.x project templates set MvcRazorCompileOnPublish
to true.