Does MVC6 support Precompiled Views?

后端 未结 3 1365
礼貌的吻别
礼貌的吻别 2020-12-09 18:25

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 .

3条回答
  •  再見小時候
    2020-12-09 18:55

    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,

    1. Add a reference to “Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design” under the “dependencies” section.
    2. Add a reference to “Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tools” under the tools section
    3. 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%"
    }
    

提交回复
热议问题