Visium.Anima.Extensions.Console 1.0.0-alpha.16

This is a prerelease version of Visium.Anima.Extensions.Console.
dotnet add package Visium.Anima.Extensions.Console --version 1.0.0-alpha.16
                    
NuGet\Install-Package Visium.Anima.Extensions.Console -Version 1.0.0-alpha.16
                    
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="Visium.Anima.Extensions.Console" Version="1.0.0-alpha.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Visium.Anima.Extensions.Console" Version="1.0.0-alpha.16" />
                    
Directory.Packages.props
<PackageReference Include="Visium.Anima.Extensions.Console" />
                    
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 Visium.Anima.Extensions.Console --version 1.0.0-alpha.16
                    
#r "nuget: Visium.Anima.Extensions.Console, 1.0.0-alpha.16"
                    
#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 Visium.Anima.Extensions.Console@1.0.0-alpha.16
                    
#: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=Visium.Anima.Extensions.Console&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Visium.Anima.Extensions.Console&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Tool

Anima.Extensions.Console

Utilities for quickly creating console applications with Microsoft.Extensions.DependencyInjection.

Usage

The following sections explain how to create a basic console application using this library.

1. Create an application menu

Add console commands to your application by implementing IConsoleCommand or IAsyncConsoleCommand into any classes you like.

public class HelloWorldCommand : IConsoleCommand
{
    public string Path => "Print Commands/Print Hello World";
    
    public string Description => "Displays the words \"Hello World\" in the console.";
    
    public void Execute()
    {
        Console.WriteLine("Hello, World!");
    }
}

The above example will add the Print Hello World command to a menu named Print Commands, which when selected, will write Hello, World! to the console.

2. Set up the application

The following example uses a top-level statements Program.cs, but this will work with any setup of console application that has a configurable IServiceCollection.

First, call the AddAnimaConsole extension method to add necessary services to the service container.

var services = new ServiceCollection()
    .AddAnimaConsole()
    .BuildServiceProvider();

Resolve IConsoleApplicationBuilderFactory from the service provider and create a new builder instance.

var factory = services.GetRequiredService<IConsoleApplicationBuilderFactory>();
var builder = factory.Create();

Build the application. This example adds a red application name title when the app starts, then builds the app instance.

var application = builder
    .WithTitle("My Console Application", ConsoleColor.Red)
    .Build();

3. Run the application

There are two ways to do this.

await application.RunAsync();

This above will run the application indefinitely, until the user selects the Exit option from the root application menu. The exit command is added to the end of the root menu automatically by this library.

Alternatively, the menu can be run through just once before returning control back to the application.

await application.RunOnceAsync();

Once a command is selected, it will be executed, then the application will close if there is nothing after this line.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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
1.0.0-alpha.16 113 8/18/2025
1.0.0-alpha.15 135 4/24/2025