mcpField
N
neo-dotnet-tag-helper

neo-dotnet-tag-helper

github.com/benknightdarkDevelopment735 installsUpdated 4d ago
Repository

About neo-dotnet-tag-helper

neo-dotnet-tag-helper is a skill for designing and generating custom Razor Tag Helpers in C#. It gathers requirements for tags and attributes, then guides implementation and validation without generating `.cshtml` files.

Key features

  1. 01Clarifies tag and attribute requirements
  2. 02Generates C# Tag Helper classes
  3. 03Uses TagBuilder for HTML construction
  4. 04Guidance for dependency injection and context
  5. 05Checks typing and thread safety

Use cases

  1. 01Building reusable custom HTML tags
  2. 02Encapsulating UI logic in C#
  3. 03Generating a Tag Helper with service dependencies

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/benknightdark/neo-skills --skill neo-dotnet-tag-helper

After installing, type/neo-dotnet-tag-helperin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

reference/
anti-patterns.md
coding-style.md
patterns.md

Details

From the project README

.NET Tag Helper Expert Skill

Trigger On

  • The user requests to create, generate, or design a custom Razor Tag Helper in C#.
  • The user wants to encapsulate complex HTML/UI logic into reusable custom tags without using Partial Views or CSHTML.
  • The target framework is .NET 6.0 (LTS) and above.

Workflow (Generator Pattern)

Follow these steps exactly to create robust, high-performance C# Tag Helpers.

Step 1: Perceive & Gather Requirements (Inversion)

Before writing any code, ask the user to clarify the following if not already provided:

  1. Target HTML Tag: What is the name of the custom tag in HTML? (e.g., <my-button>, <user-card>)
  2. Properties: What parameters/attributes should this tag accept? (e.g., theme, is-active, user-id)
  3. Dependencies (DI): Does this tag need to query a database or call a service? (Needs Dependency Injection)
  4. Context: Does it need to access ViewContext (e.g., to generate URLs or check model state)?
Step 2: Reason & Design (Planning)

Based on the answers:

  • Class Naming: Ensure the class name ends with TagHelper (e.g., MyButtonTagHelper).
  • Target Element: Apply [HtmlTargetElement("my-button")].
  • Properties: Map HTML kebab-case attributes to C# PascalCase properties. Apply [HtmlAttributeName("is-active")] if necessary.
  • Method Selection:
    • If no IO/Async operations, override Process.
    • If using DI for database/API calls, override ProcessAsync.
Step 3: Act (Code Generation)

Generate the complete C# class. Strictly adhere to the following rules:

  1. Inherit from Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.
  2. Do NOT generate .cshtml files. All HTML must be constructed using TagBuilder inside the C# class.
  3. If ViewContext is needed, use [ViewContext] and [HtmlAttributeNotBound].
  4. Manage content properly using output.TagName, output.Attributes.SetAttribute, and output.Content.SetHtmlContent.
  5. Ensure Thread-Safety (do not store request-specific state in instance fields unless injected as scoped/transient).
Step 4: Validate (Quality Check)

Review the generated code against these criteria before presenting it:

  • Are all properties strongly typed?
  • Is TagBuilder used instead of string concatenation for HTML elements?
  • Is ProcessAsync used correctly if awaiting tasks?

Deliverable

Present the C# code wrapped in a markdown code block. Briefly explain how to register it in _ViewImports.cshtml (e.g., @addTagHelper *, YourAssemblyName).

Documentation

Official References
Internal References

Comments

Markdown supported