asp.net-mvc - ASP .NET Core MVC 在没有嵌入资源的情况下从 `*.views.dll` 文件中添加视图
问题描述
我一直在尝试在*.Views.dll
可能的视图之间导入已编译视图的 ASP.NET Core MVC 视图。
警告!
我无意*.views.dll
在正在编译的资源中添加该文件,但之后。
为了清楚起见,正在运行的程序必须从文件夹中获取文件并通过将程序集文件的内容添加到其视图中来读取它
要获得更多信息,我会给你 qule 中的演讲链接已连接
此外,我不想使用嵌入式资源,因为视图仍然清晰。
我试过这个
services.AddMvc().ConfigureApplicationPartManager(apm =>{
var part = new AssemblyPart(AssemblyLoadContext.Default.LoadFromAssemblyPath("C:\\Users\\gianf\\source\\repos\\ViewTestPlugin2\\plug\\bin\\Debug\\netcoreapp2.1\\plug.Views.dll"));
apm.ApplicationParts.Add(part);
});
解决!!!
查看 * .views.dll 文件的程序集我注意到了这一点
[assembly: ProvideApplicationPartFactory("Microsoft.AspNetCore.Mvc.ApplicationParts.CompiledRazorAssemblyApplicationPartFactory, Microsoft.AspNetCore.Mvc.Razor")]
因此,我尝试像这样手动设置它:
services.AddMvc().ConfigureApplicationPartManager(apm =>
{
var a = new CompiledRazorAssemblyApplicationPartFactory();
foreach (var b in a.GetApplicationParts(AssemblyLoadContext.Default.LoadFromAssemblyPath("C:\\Users\\gianf\\source\\repos\\ViewTestPlugin2\\plug\\bin\\Debug\\netcoreapp2.1\\plug.Views.dll")))
apm.ApplicationParts.Add(b);
});
所以它有效,我认为 AssemblyPart 坏了
解决方案
推荐阅读
- dialogflow-es - 为帐户名称的多空格分隔用户短语设置哪种 Dialogflow 实体类型
- django - 是否存在干扰“授权:承载 {token}”数据的 AWS 入站策略?
- python - 如何在 Streamlit 上更改面积图的标签?
- java - Logback Spring - 在运行时使用 jar 外部的外部 yaml 文件更改日志级别
- c# - 错误:输入字符串的格式不正确
- spring-boot - 关于 ResponseStatusException 返回错误对象中的空消息字段
- json - Azure 资源管理器:Web 应用槽配置:应用服务身份验证
- google-apps-script - 我需要将 Google Sheet 1 中的数据复制到 Google Sheet2 中的一行
- python - 使用贪心方法的活动选择问题的不同解决方案
- angular - 是否可以在 TypeScript 中设置 Angular SelectionModel 对象的 CompareWith 函数