How to compile cshtml before runtime

前端 未结 3 509
南笙
南笙 2020-12-01 03:30

I believe I read somewhere there is a setting in one of the project files that will allow you to compile the .cshtml files when building your Visual Studio proj

相关标签:
3条回答
  • 2020-12-01 03:52

    Besides the true setting, you still need to ensure below setting is active in your csproj:

    <Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
    </Target>
    
    0 讨论(0)
  • 2020-12-01 03:59

    Set <MvcBuildViews>true</MvcBuildViews> in the <PropertyGroup> element of your .csproj file.

    0 讨论(0)
  • 2020-12-01 04:04

    MvcBuildViews is often mistakenly, as it doesn’t precompile views in the terms you'd like.

    MvcBuildViews builds views temporarily and gives build results back to building process to show possible build error in VS errors window.

    For achieving a real precompilation of views for production release, you have to properly set specific values in the Publish Web App configuration window of your project.

    See here for the main article about how to do it, and here for going deeper on how to do it via msBuild and Azure.

    0 讨论(0)
提交回复
热议问题