【发布时间】:2018-01-30 12:50:39
【问题描述】:
在带有 razor 视图的 ASP.NET Core 2.0 项目中,我正在运行时加载一个包含 TagHelpers 的程序集。
当 .dll 位于项目的 bin 文件夹中或将 TagHelpers 项目作为依赖项添加到项目时,标签由 taghelpers 解析。
但是,当程序集在 bin 文件夹外加载时,即使程序集成功加载,TagHelpers 也不起作用。
从 bin 外的文件夹加载程序集时,如何让 TagHelpers 工作?
public void ConfigureServices(IServiceCollection services)
{
var asm = AssemblyLoadContext.Default.LoadFromAssemblyPath(@"D:\SomeTagHelpers\bin\Debug\netcoreapp2.0\SomeTagHelpers.dll");
var part = new AssemblyPart(asm);
var builder = services.AddMvc();
builder.ConfigureApplicationPartManager(appPartManager => appPartManager.ApplicationParts.Add(part));
builder.AddTagHelpersAsServices();
}
【问题讨论】:
标签: c# asp.net-core asp.net-core-tag-helpers