Answer for RC-1
- Create the following
RazorPreCompilation class:
namespace YourApp.Compiler.Preprocess { public sealed class RazorPreCompilation : RazorPreCompileModule { protected override bool EnablePreCompilation(BeforeCompileContext context) => true; } }
- Puts this class in {root} / Compiler / Preprocess.

- Add a call to
AddPrecompiledRazorViews in your ConfigureServices method.
public void ConfigureServices(IServiceCollection services) {
As indicated in other answers, when the views are precompiled, you lose the ability to change them while the application is running. In addition, it seems that you sometimes have to rebuild your project (as opposed to just building) for the new code changes to take effect. For example, fixing a typo in a call to the Razor method may still cause a compilation error until you restore the project.
Directive Update
If you want this start to be done using preprocess directives, wrap them around the AddPrecompiledRazorViews call as follows:
public void ConfigureServices(IServiceCollection services) {
source share