参考ASP.NET核心类库



我有一个包含自定义标签助手的核心类库。我想在核心Web应用程序中添加它作为参考。

i右键单击Visual Studio中的项目,选择"添加参考"并浏览到文件夹中,然后选择DLL。

但是当我尝试使用@addTagHelper时,我会得到:

无法解析包含汇编" lc_public_core"的taghelper。错误:无法加载文件或汇编'lc_public_core,culture =中性,publickeytoken = null'。系统找不到指定的文件。

我的代码:

lc_public (类库(

namespace LC_PUBLIC_CORE.TagHelpers
{
    [HtmlTargetElement("LC_meta")]
    public class MetaTagHelper : TagHelper
    {
        private IHostingEnvironment _env;
        [HtmlAttributeName("filename")]
        public string Filename { get; set; } = "default.txt";
        public MetaTagHelper(IHostingEnvironment env)
        {
            _env = env;
        }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.Content.SetContent(System.IO.File.ReadAllText(System.IO.Path.Combine(_env.WebRootPath, "META", this.Filename)));
        }
    }
}

asp_net_core_standard (Web应用程序(-_viewimports.cshtml

@using ASP_NET_CORE_Standard
@using LC_PUBLIC_CORE
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, LC_PUBLIC_CORE

我需要添加任何其他代码吗?

我通过创建一个新解决方案并将两个项目添加到解决方案中,从而使它起作用。然后在ASP_NET_CORE_STANDARD中添加了对LC_PUBLIC_CORE项目的引用。

_viewimports.cshtml

@using ASP_NET_CORE_Standard
@using LC_PUBLIC_CORE
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, LC_PUBLIC_CORE

最新更新