Blzr.Components.CommandLine 10.1.0

dotnet add package Blzr.Components.CommandLine --version 10.1.0
                    
NuGet\Install-Package Blzr.Components.CommandLine -Version 10.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Blzr.Components.CommandLine" Version="10.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Blzr.Components.CommandLine" Version="10.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Blzr.Components.CommandLine" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Blzr.Components.CommandLine --version 10.1.0
                    
#r "nuget: Blzr.Components.CommandLine, 10.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Blzr.Components.CommandLine@10.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Blzr.Components.CommandLine&version=10.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Blzr.Components.CommandLine&version=10.1.0
                    
Install as a Cake Tool

Blazor.CommandLine (Blazor.Console)

Actions Status NuGet version (Blzr.Components.CommandLine)

A simple, web-based command-line interface (CLI) component for ASP.NET Core Blazor applications.

<p align="center"> <img src="https://github.com/ardacetinkaya/Blazor.Console/blob/main/screenshots/1.png" /> </p>

Why this exists?

This is a simple Blazor component to be able to add and run some commands for an application. The motivation behind this simple component is to manage applications and run maintenance tasks directly from the browser, without needing to SSH into a server or expose complex API endpoints with some additional fancy UI. It wraps the powerful System.CommandLine library, giving you a familiar CLI experience right in your Blazor app.

It's great for some simple operations:

  • Clearing caches
  • Triggering background jobs
  • Viewing local application files or system status
  • Changing runtime settings
  • or many more

Features

  • Web-based Terminal: Familiar command-line look and feel.
  • Easy Integration: Drop it into any Blazor page.
  • Custom Commands: Create your own commands by inheriting from a base class.
  • Arguments & Options: Supports standard CLI arguments and options (e.g., --force, -v).
  • Async Support: Handles long-running tasks with loading indicators.
  • Built on System.CommandLine: Uses the standard .NET command line parser.

Installation

Install the package via NuGet:

dotnet add package Blzr.Components.CommandLine

Setup

  1. Register Services: In your Program.cs (or Startup.cs), add the command line services:

    builder.Services.AddCommandLine();
    
  2. Configure Middleware: Map the static assets (CSS/JS) in your request pipeline:

    app.UseCommandLine(app.Environment.WebRootPath);
    
  3. Add Styles: Add the CSS reference to your _Host.cshtml (Blazor Server) or index.html (Blazor WebAssembly):

    <link href="_content/Blzr.Components.CommandLine/styles.css" rel="stylesheet" />
    

    (Note: Check the actual path in your project, it might be Blazor.CommandLine/styles.css depending on older versions, but _content/... is standard for libraries).

Usage

Add the component to any Razor page (e.g., Index.razor):

@page "/"
@using Blazor.CommandLine
@using Blazor.Components.CommandLine
@using Blazor.Components.CommandLine.Console

<BlazorCommandLine @ref="_console" Name="My App CLI" />

@code {
    private BlazorCommandLine _console;

    protected override Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            // Register your custom commands here
            _console.Commands.Add(new MyCustomCommand());
        }
        return base.OnAfterRenderAsync(firstRender);
    }
}

Creating Custom Commands

To create a command, inherit from BaseCommand and override the Execute or ExecuteAsync method.

using Blazor.CommandLine.Command;
using Blazor.Components.CommandLine.Console;

public class MyCustomCommand : BaseCommand
{
    public MyCustomCommand() : base("my-cmd", "A sample custom command")
    {
        // Define options: becomes --target (or -o1)
        AddOption("target", "Specify the target to operate on");
    }

    protected override bool Execute(ConsoleOut console, params KeyValuePair<string, string>[] options)
    {
        // Retrieve option values
        var target = options.FirstOrDefault(o => o.Key == "target").Value;

        if (string.IsNullOrEmpty(target))
        {
            console.Write("Error: Target is required.");
            return false;
        }

        console.Write($"Executing command on target: {target}");
        return true;
    }
}

Async Commands

For long-running operations, use ExecuteAsync. The UI will show a loading indicator.

public class LongRunningCommand : BaseCommand
{
    public LongRunningCommand() : base("process", "Starts a long process", longRunning: true)
    {
    }

    protected override async Task<bool> ExecuteAsync(ConsoleOut console, CancellationToken ct, params KeyValuePair<string, string>[] options)
    {
        console.Write("Starting process...");
        await Task.Delay(3000, ct); // Simulate work
        console.Write("Process completed successfully!");
        return true;
    }
}

<p align="center"> <img src="https://github.com/ardacetinkaya/Blazor.Console/blob/main/screenshots/2.png" /> </p>

References

Contributing

This project was built to solve a specific need, but I'm sure there are many ways it can be improved. If you have ideas for new features, better styling, or bug fixes, I'd really appreciate your help!

Feel free to open an issue to discuss ideas or submit a pull request. Let's make this a much useful tool.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.1.0 82 12/29/2025
10.0.0 42 12/28/2025
5.0.0 1,208 11/24/2020
3.1.0 796 1/27/2020
3.0.0 450 1/3/2020
2.0.0 1,254 12/17/2019