PrecompiledMvcEngine 仍然使用共享物理视图
PrecompiledMvcEngine still uses shared physical views
我已经在应用启动中注册了一个 PrecompilecMvcEngine 来预编译我的 razor 视图。构建包正确排除了 ~/Views/ 目录中的所有 .cshtml 文件,但是 if 目录中存在视图,它继续使用 .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);
}
}
}
正如 CodeCaster 所写,在 PrecompiledMvcEngine
上将 PreemptPhysicalFiles
设置为 true
解决了问题。
我已经在应用启动中注册了一个 PrecompilecMvcEngine 来预编译我的 razor 视图。构建包正确排除了 ~/Views/ 目录中的所有 .cshtml 文件,但是 if 目录中存在视图,它继续使用 .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);
}
}
}
正如 CodeCaster 所写,在 PrecompiledMvcEngine
上将 PreemptPhysicalFiles
设置为 true
解决了问题。