In < MVC6 I could have .cshtml files pre-compiled on publish, so that they didn\'t have to be compiled on first hit when requested.
Is it possible to precompile .
Finally Razor view pre-compilation is supported as of ASP.NET Core 1.1.
Here is the announcement: Announcing the Fastest ASP.NET Yet, ASP.NET Core 1.1 RTM
It said:
The Razor syntax for views provides a flexible development experience where compilation of the views happens automatically at runtime when the view is executed. However, there are some scenarios where you do not want the Razor syntax compiled at runtime. You can now compile the Razor views that your application references and deploy them with your application. To enable view compilation as part of publishing your application,
- Add a reference to “Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design” under the “dependencies” section.
- Add a reference to “Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tools” under the tools section
- Add a postpublish script to invoke view compiler:
"scripts": {
"postpublish": "dotnet razor-precompile --configuration %publish:Configuration% --framework %publish:TargetFramework% --output-path %publish:OutputPath% %publish:ProjectPath%"
}