Does MVC6 support Precompiled Views?

后端 未结 3 1363
礼貌的吻别
礼貌的吻别 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:35

    csproj (VS 2017) Answer

    Add a reference to Microsoft.AspNetCore.Mvc.Razor.ViewCompilation:

    
        
    
    

    Turn on razor view compilation upon publishing the project.

    
        true
    
    

    See this GitHub issue for more details.

    xproj and project.json (VS 2015) Answer

    Razor Pre-compilation was dropped in ASP.NET Core 1.0 MVC 6 RC2 but was brought back in ASP.NET Core 1.1 using a tool which you can add like so:

    1. Add a reference to Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design under the dependencies section like so:
    "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design": {
        "type": "build",
        "version": "1.1.0-preview4-final"
    }
    
    1. Add a reference to Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tools under the tools section like so:
    "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tools": "1.1.0-preview4-final",
    
    1. 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%"
    }
    

提交回复
热议问题