【问题标题】:How can I fix compilation for relative paths using StackExchange.Precompilation?如何使用 StackExchange.Precompilation 修复相对路径的编译?
【发布时间】:2017-03-09 20:56:20
【问题描述】:

对于https://github.com/StackExchange/StackExchange.Precompilation

我们在安装了 StackExchange.Precompilation 的单独库中有一些共享视图。我们必须将这些视图与普通 Web 项目的视图一起加载。我们在两个项目中都从 NuGet 安装了最新版本的 StackExchange.Precompilation。我正在像这样进行程序集加载:

// Register precompiled view engine
ViewEngines.Engines.Clear();

List<Assembly> viewAssemblies = new List<Assembly> { typeof(HomeController).Assembly };
viewAssemblies.AddRange(AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.ToLower().Contains(".web")));

Log.Debug().Message("Looking for views in: {0}", string.Join(", ", viewAssemblies.Select(a => a.FullName))).Write();

ViewEngines.Engines.Add(new PrecompiledViewEngine(viewAssemblies.ToArray()));

在 web 项目中,我们以正常方式返回视图:return View("Index"); 当使用PrecompiledViewEngine 时,我们会在尝试呈现这样的相对名称时出现错误:

The view 'Index' or its master was not found or no view engine supports the searched locations. 
The following locations were searched: 
~/util/Views/Example/Index.cshtml 
~/util/Views/Shared/Index.cshtml

util 是 IIS 中应用程序的别名。我们没有任何个注册区域。

当我从 GitHub 复制 PrecompiledViewEngine 类时 - 它起作用了!我是否遗漏了一些可以使通过 NuGet 分发的版本正常工作的内容?

【问题讨论】:

    标签: stackexchange pre-compilation


    【解决方案1】:

    复制代码被证明是行不通的。我当时一定在尝试其他方法,使其适用于特定案例。

    问题实际上是 StackExchange.Precompilation 中的一个错误。我在那里创建了一个问题:https://github.com/StackExchange/StackExchange.Precompilation/issues/12

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-18
      • 2011-12-16
      • 1970-01-01
      相关资源
      最近更新 更多