c# - PrecompiledMvcEngine 仍然使用共享物理视图
问题描述
我已经在 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);
}
}
}
解决方案
正如CodeCaster所写,设置PreemptPhysicalFiles
为true
onPrecompiledMvcEngine
解决了这个问题。
推荐阅读
- php - PHP正则表达式检查长度而不使用前瞻
- javascript - javascript的默认导出代码在tailwindcss中不起作用
- python - kmeans 与其他变量的散点图
- javascript - 如何从获取数据响应中构造新的 JSON?
- reactjs - 使用 Authentication 标头的基于令牌的身份验证给出 403 禁止错误
- php - 如何绕过在奇怪时区拥有 mySQL 数据库的主机
- r - kernelUD 中的错误:xy 应在二维中定义
- python - 如何根据 PyQt5 中的 Contents 获取框架的最小尺寸/固定尺寸?
- svm - 理解 Python 的 roc_curve、svm 例子
- excel - 将单元格的列值分配给变量时出现“应用程序或对象定义错误”