1

对于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 中应用程序的别名。我们没有注册任何区域。

PrecompiledViewEngine当我从 GitHub复制课程时 -它有效!我是否遗漏了一些可以使通过 NuGet 分发的版本正常工作的东西?

4

1 回答 1

1

复制代码结果是行不通的。当时我一定在尝试其他方法,使其适用于该特定情况。

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

于 2017-03-09T12:56:20.830 回答