对于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 分发的版本正常工作的东西?