ConsoleMVC.Framework
1.33.0
dotnet add package ConsoleMVC.Framework --version 1.33.0
NuGet\Install-Package ConsoleMVC.Framework -Version 1.33.0
<PackageReference Include="ConsoleMVC.Framework" Version="1.33.0" />
<PackageVersion Include="ConsoleMVC.Framework" Version="1.33.0" />
<PackageReference Include="ConsoleMVC.Framework" />
paket add ConsoleMVC.Framework --version 1.33.0
#r "nuget: ConsoleMVC.Framework, 1.33.0"
#:package ConsoleMVC.Framework@1.33.0
#addin nuget:?package=ConsoleMVC.Framework&version=1.33.0
#tool nuget:?package=ConsoleMVC.Framework&version=1.33.0
ConsoleMVC
An MVC framework for console applications, inspired by ASP.NET Core MVC.
ConsoleMVC brings the familiar Controller-ViewModel pattern to console apps, with convention-based routing, automatic discovery through a generated route table, and Razor-like .cvw view templates powered by a C# source generator.
Quick Start
# Install the template
dotnet new install ConsoleMVC.Template
# Create a new project
dotnet new consolemvc -n MyApp
cd MyApp
dotnet run
How It Works
Program.cs: familiar ASP.NET-style builder:
var builder = MvcApplication.CreateBuilder(args);
builder.Services.AddSingleton<IGreetingService, GreetingService>(); // optional
using var app = builder.Build();
await app.RunAsync();
Controllers: inherit from Controller, return ActionResult:
public class HomeController : Controller
{
public ActionResult Index()
{
var model = new HomeViewModel { Title = "Hello!" };
return View(model);
}
}
Views: .cvw files with an @model directive and C-View Markup, no class boilerplate:
@model MyApp.Models.HomeViewModel
<box title="@Model.Title" border="rounded" color="cyan">
<text>@Model.Message</text>
</box>
<input name="Name" label="Your name: " required />
<menu>
<option key="1" nav="Greet/Result" post>Greet me</option>
<option key="q" quit>Exit</option>
</menu>
Models: simple DTOs:
public class HomeViewModel
{
public string Title { get; set; } = "";
}
Features
- Convention-based routing: Controllers and Views are found by name and namespace conventions, listed in a route table generated at build time
- Razor-like view engine:
.cvwfiles are compiled intoConsoleView<TModel>classes at build time by a source generator - No boilerplate: Views are plain C# code with an
@modeldirective, no class inheritance required - C-View Markup:
<box>,<text>,<separator>,<br>and<table>elements with colours, borders, alignment and word wrapping, plus@expressions and@if/@foreach; validated at compile time with errors pointing at the.cvwfile, includingnavtargets that name a missing controller or action (CVW119), the same mistakes inRedirectToActionandNavigationResultcalls (CVW120), and missing views (CVW121, with a fix that creates the view) - Responsive screens: resizing the terminal lays the current screen out again at the new width
- Full screen and scrolling:
builder.FullScreen = trueuses the terminal's alternate screen, and<scroll>pages long content with the arrow keys - Layout and themes:
<columns>(stacking on narrow terminals),min-width/max-width, and theme classes withclass="title" - Layouts:
Views/Shared/_Layout.cvwframes every screen, with<body />where the view goes - Partial views: reusable markup in
Views/Shared/{Name}.cvw, rendered with<partial name="Header" model="@Model.Title" />and checked at build time - Declarative input and navigation:
<input>fields (required, default, masked),<number>and<date>with ranges,<select>(with type-to-filter) and<radio>lists and<checkbox>(answered with the arrow keys in a terminal) collect aForm, and<menu>reads the choice and navigates - Mouse:
builder.Mouse = truemakes menu options, choices and checkboxes clickable and the wheel scroll - Keyboard shortcuts:
app.MapKey(ConsoleKey.F1, "Help/Index", "Help"),NavigationResult.Back()on Esc, and<shortcuts />to list them - Markdown:
<markdown text="@Model.Notes" />(MarkdownElement) draws headings, lists, quotes, code, emphasis and links, sanitised - Charts:
<bar-chart>with<bar />children and<sparkline values="@Model.History" />(BarChartElement,SparklineElement) - Live screens:
<progress>and<spinner>, kept up to date while an async action works withILiveDisplay.Start(element), and views that refresh on a timer with@refresh 5sorView(model).RefreshEvery(...)until the user types - Areas and modules:
Areas/{Area}/Viewswith[Area]or*.Areas.{Area}controllers andArea/Controller/Actionroutes, andbuilder.AddModule<TModule>()(IMvcModule) for controllers and views in other assemblies - Localisation:
IStringLocalizer<T>in views and controllers,builder.Localization(culture,FrameworkTexttranslated from resources, localised DataAnnotations messages), and theConsoleMVC:Culturesetting - Accessibility:
builder.ScreenReader(ScreenReaderRenderer: plain text, no borders, typed answers) andbuilder.HighContrast(Theme.CreateHighContrast()), also chosen by users with theConsoleMVC:ScreenReaderandConsoleMVC:HighContrastsettings - Secure output: model values are sanitised so they cannot inject terminal escape sequences
- Reusable rendering engine: the
ConsoleMVC.Renderingnamespace can draw elements in any console app - Familiar API:
View(),RedirectToAction(),ViewData, all the patterns you know from ASP.NET Core MVC - Navigation: Views return
NavigationResultto control app flow (NavigationResult.To(),Back(),Quit()); menus offerbackoptions and<breadcrumbs />shows the trail; route values (nav="Orders/Details?id=@order.Id") bind to action parameters - Testing: the companion package ConsoleMVC.Testing runs the application with scripted input and compares screens with snapshot files
- Configuration and logging:
builder.Configuration(appsettings.json, environment variables, command line), options withConfigure<T>,builder.EnvironmentandILogger<T>throughbuilder.Logging, with a built-in rolling file logger (builder.Logging.AddFile("logs/app.log")) - Validation: posted forms are checked with DataAnnotations (
[Required],[Range],[EmailAddress], …) before the action runs; useModelState.IsValid,View("Form", model)and<errors />as in ASP.NET Core MVC - Dependency injection:
builder.Services(Microsoft.Extensions.DependencyInjection); constructor injection into controllers,@inject Type Namein views, one scope per screen - Async actions and middleware:
Task<ActionResult>actions,RunAsync(token), andapp.Use(...)/UseMiddleware<T>()around every action - Native AOT and trimming: a generated route table (
IRouteTable) replaces reflection, sodotnet publish -p:PublishAot=trueworks with no warnings - Remote sessions:
app.ServeAsync(new TerminalServerOptions())or theConsoleMVC:Servesetting serves the application over Telnet (optionally TLS) with one session per client;ITerminalSessiontells users apart, andRemoteTerminalplusRunSessionAsyncrun a session over any stream - Live reload:
dotnet watchapplies.cvwand C# edits to the running app from the next screen; new pages are discovered automatically - Form data posting: Views collect user input via
Console.ReadLine()and post it to controller actions usingNavigationResult.To("Controller", "Action", formData). The framework automatically binds the data to action method parameters, either as individual simple types (int,string, etc.) or as a complex model class with matching property names
IDE Support
For .cvw file recognition, syntax highlighting, and icon support in JetBrains Rider, install the ConsoleMVC CVWSupport plugin:
Documentation
For full documentation and source code, visit the GitHub repository.
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.Configuration.CommandLine (>= 10.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.0)
- Microsoft.Extensions.Configuration.Json (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Localization (>= 10.0.0)
- Microsoft.Extensions.Logging (>= 10.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 10.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ConsoleMVC.Framework:
| Package | Downloads |
|---|---|
|
ConsoleMVC.Testing
Test ConsoleMVC applications end to end: run them with scripted lines and keys, capture every screen as plain text, assert on the routes visited, and compare screens with snapshot files. Works with xUnit, NUnit and MSTest. |
GitHub repositories
This package is not used by any popular GitHub repositories.