猿问

PrecompiledMvc​​Engine 仍然使用共享物理视图

我已经在 app start 中注册了一个 PrecompilecMvcEngine 来预编译我的剃刀视图。构建包正确地排除了 ~/Views/ 目录中的所有 .cshtml 文件,但如果目录中存在视图,它会继续使用 .cshtml 文件,无论是否编译。


例如,如果部署目录中存在视图 ~/Shared/Layout.cshtml,则始终使用该视图。


如何确保从不使用物理视图?


我有以下代码:


[assembly: WebActivatorEx.PostApplicationStartMethod(typeof(SomeBaseNamespace.Views.RazorGeneratorMvcStart), "Start")]


namespace SomeBaseNamespace.Views

{

    public static class RazorGeneratorMvcStart

    {

        public static void Start()

        {

            var engine = new PrecompiledMvcEngine(typeof(RazorGeneratorMvcStart).Assembly) 

            {

                UsePhysicalViewsIfNewer = false // I would expect this to prevent the engine from using physical views.

            };


            ViewEngines.Engines.Insert(0, engine);

        }

    }

}


扬帆大鱼
浏览 212回答 1
1回答

炎炎设计

正如CodeCaster所写,设置PreemptPhysicalFiles为trueonPrecompiledMvcEngine解决了这个问题。
随时随地看视频慕课网APP
我要回答