内置Microsoft.AspNetCore.Mvc.TagHelpers
工作正常,但是,每当我尝试导入我构建的自定义标记帮助程序时,我在调试时会收到以下错误:
我试图从在asp.net核心项目的根目录下构建的类导入两者,以及在asp.net核心项目外部的类库中构建的类。以下是与自定义标记帮助程序相关的代码:
RepeatTagHelper.cs(在ASP.NET核心项目根目录中)
using Microsoft.AspNetCore.Razor.TagHelpers;
using System.Threading.Tasks;
namespace mvc_form
{
/// <summary>
/// <repeat count-of-things="5">HTML</repeat>
/// </summary>
public class RepeatTagHelper : TagHelper
{
public int CountOfThings { get; set; }
public async override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
for (var i = 0; i < CountOfThings; i++)
{
output.Content.AppendHtml(await output.GetChildContentAsync(useCachedResult: false));
}
}
}
}
RepeatTagHelper.cs(在.NET核心类库中)
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.TagHelpers;
namespace core_resources.TagHelpers
{
/// <summary>
/// <repeat count-of-things="5">HTML</repeat>
/// </summary>
public class RepeatTagHelper : TagHelper
{
public int CountOfThings { get; set; }
public async override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
for (var i = 0; i < CountOfThings; i++)
{
output.Content.AppendHtml(await output.GetChildContentAsync(useCachedResult: false));
}
}
}
}
_ViewImports.cshtml(引用ASP.NET核心项目中定义的标记助手时
@using mvc_form
@using mvc_form.Models
@using mvc_form.Models.AccountViewModels
@using mvc_form.Models.ManageViewModels
@using Microsoft.AspNetCore.Identity
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, mvc_form
_ViewImports.cshtml(引用类库中定义的标记助手时)
@using mvc_form
@using mvc_form.Models
@using mvc_form.Models.AccountViewModels
@using mvc_form.Models.ManageViewModels
@using Microsoft.AspNetCore.Identity
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, core_resources.TagHelpers
我已将完整的解决方案添加到GitHub
答案 0 :(得分:3)
使用您当前的设置,生成的.dll文件名为:core-resources.dll
所以你需要这样注册:
@addTagHelper *, core-resources
或为outputName
项目定义自定义core-resources
:
"buildOptions": {
"outputName": "core_resources"
},
然后以这种方式使用这个新名称:
@addTagHelper *, core_resources