首页 > 解决方案 > 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 坏了

标签: asp.net-mvcasp.net-coreasp.net-core-mvc

解决方案


推荐阅读