是否可以将ASP.NET Core Web应用程序配置为使用编译到类库/单独程序集中的EditorTemplate
razor页面?
作为示例,以下问题详细说明了如何将ViewComponent
编译到类库中。很遗憾,我无法找到有关对EditorTemplate
页面执行相同操作的任何信息。
答案 0 :(得分:4)
在GitHub的 pranavkm 的帮助下解决了这个问题。我要求的步骤如下:
在ConfigureServices()
中的Web应用程序中,将类模块程序集添加为文件提供程序(通过程序集中任何类或接口的类型获取程序集):
var library = typeof(Library.SomeClass).GetTypeInfo().Assembly;
services.AddMvc()
.AddRazorOptions(options =>
{
options.FileProviders.Add(new EmbeddedFileProvider(library));
});
在类模块中:确保包含编辑器模板的目录结构与在Web应用程序Views\Shared\EditorTemplates
中的目录结构相同。
在课程模块中:将剃须刀视图作为资源嵌入,将以下内容添加到project.json
:
"buildOptions": {
"embed": "Views/**"
}