代码之家  ›  专栏  ›  技术社区  ›  Andreas Christiansen

预编译的MVCEngine仍然使用共享的物理视图

  •  0
  • Andreas Christiansen  · 技术社区  · 7 年前

    我已经在app start中注册了预编译MVCEngine,以预编译我的razor视图。生成包正确地排除了所有。/Views/directory中的cshtml文件,但是 如果 目录中存在视图,它将继续使用。cshtml文件,无论是否编译。

    例如,视图~/共享/布局。如果部署目录中存在cshtml,则始终使用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);
            }
        }
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Andreas Christiansen    7 年前

    CodeCaster 写入,设置 PreemptPhysicalFiles true 在…上 PrecompiledMvcEngine 解决了问题。