Console App Project Template for .NET 7

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.jsonThe JSON configuration file for the console app
Program.csThe 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:

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.

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Dmitry Pavlov
1 year ago

Does it support command completions by TAB?