我有一個包含自定義標籤助手的核心類庫。我想在覈心Web應用程序中添加這個參考。引用ASP.NET核心類庫
我右鍵單擊Visual Studio中的項目,選擇添加引用並瀏覽到該文件夾並選擇該dll。
但是,當我嘗試使用@addTagHelper
我得到:
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.
我的代碼:
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
是否需要添加其他代碼?
你最後@addTagHelper線使用比第二最後一個不同的(和過時)格式。此外,通配符也完全不同。 @addTagHelper的第一個參數用於標籤助手類名(全是'*'),第二個是標籤助手所在的名稱空間 – Tseng
@tseng我已經改變了格式,但仍然是相同的錯誤。如果我使用LC_PUBLIC_CORE.TagHelpers,則得到「**無法解析包含程序集的TagHelper'LC_PUBLIC_CORE.TagHelpers'**」,在引用上定義Copy Local = true也沒有任何作用 – TheRuler
您是否在更改解決方案後重建瞭解決方案?有些東西沒有立即被拾起(即EF核心模型變化和某些剃刀方面,即腳手架) – Tseng