Reputation: 4068
I have an Core Class Library containing custom Tag Helpers. I want to add this as a reference in a Core Web Application.
I right click on the project in Visual Studio, selects Add Reference and browses to the folder and choose the dll.
But when I try to use @addTagHelper
I get:
Cannot resolve TagHelper containing assembly 'LC_PUBLIC_CORE'. Error: Could not load file or assembly 'LC_PUBLIC_CORE, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
My code:
LC_Public (Class Library)
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 Application) - _ViewImports.cshtml
@using ASP_NET_CORE_Standard
@using LC_PUBLIC_CORE
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, LC_PUBLIC_CORE
Do I need to add any additional code?
Upvotes: 0
Views: 888
Reputation: 4068
I got it working by creating a new Solution and added both Projects to the solution. Then added a reference to the LC_PUBLIC_CORE project in ASP_NET_CORE_Standard.
_ViewImports.cshtml:
@using ASP_NET_CORE_Standard
@using LC_PUBLIC_CORE
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, LC_PUBLIC_CORE
Upvotes: 0