In a previous blog post Developing Console Apps with .NET, I demonstrated how to develop command-line programs from scratch including support for built-in help, arguments, configuration, logging, dependency injection, and more.
Rather than repeating this process for every new console app, I decided to build a brand new .NET 7 project template. In this post, I’ll show you how to install the new template, create a console app using the template, and then I’ll provide a brief overview of its design and capabilities. Let’s get started!
Create a new app
You will need to install .NET 7.0 SDK and the new template before you can create a new project. Once .NET 7 is installed, open a console window and run the following command to install the template:
dotnet new install JasonTaylorDev.RapidConsole
After the template has been installed successfully, you can create a new console app project using the following command:
dotnet new rapid-console --output AwesomeConsole
The new project will be created inside an AwesomeConsole folder. Run the console app with the following command:
cd AwesomeConsole
dotnet run
Once installed, you can also create an Rapid Console App using Visual Studio:
Exploring the project
The new project leverages features from Spectre.Console, which is a library that makes it easier to create beautiful console applications. It follows established industry conventions, and so depending on your experience, using a console app built with Spectre.Console may feel quite natural. Try some of the following commands from the project folder:
dotnet run
dotnet run --help
dotnet run --version
dotnet run forecasts 5
dotnet run forecasts 5 --unit Celsius
The organisation of the folders and files within the project is very clean. The following table briefly describes the project structure:
Common/ | Contains implementations for ITypeRegistrar and ITypeResolver , these types provide dependency injection support for Spectre.Console |
WeatherForecasts/ | A feature folder, containing all files relevant to the forecasts command. Storing commands in individual folders keeps the structure organised and clean |
appsettings.json | The JSON configuration file for the console app |
Program.cs | The entry point of the console app, leveraging top-level statements. Configures the .NET Generic Host, the Spectre.Console app, and adds the available commands, e.g. WeatherForecastCommand |
This was just a brief overview, so be sure to check out the recommended resources in the next section to learn more.
Next steps
In this post, I demonstrated how to develop console apps using the new Rapid Console App project template. I hope you find the template useful, if you do, please give it a star on GitHub. To learn more, please review the following resources:
- Rapid Console .NET Template | GitHub
- .NET Generic Host – .NET | Microsoft Learn
- Spectre.Console – Getting Started | SpectreConsole.net
Do you have any suggestions on how to improve this template? I’d love to hear from you!
Thanks for reading, please feel free to post any questions or comments below.
Does it support command completions by TAB?
Not yet, it looks like there are some options though. Spectre.Console has a draft PR and some other libraries support tab completion. That would be a great addition!