An opinionated .NET source package simplifying bootstrapping console applications with IoC, command-line parsing, logging, and more.
$ dotnet add package Devlead.ConsoleDevlead.Console is a streamlined NuGet source package designed to accelerate the development of .NET console applications. By providing out-of-the-box configurations for Inversion of Control (IoC), command-line parsing, logging, and other essential utilities, Devlead.Console allows developers to focus on building business logic rather than setting up foundational components.
AzureRepos to true)dotnet add package Devlead.Console
Here's how to create a console application using Devlead.Console, which comes with sensible defaults to streamline your setup. Additionally, you can utilize optional partial methods to tailor the project to your specific needs:
public partial class Program
{
// Configure in-memory settings (useful for development/testing)
static partial void ConfigureInMemory(IDictionary<string, string?> configData)
{
configData.Add("TestService__Version", "1.0.0.0");
}
// Register your services
static partial void AddServices(IServiceCollection services)
{
services
.AddOptions<TestServiceSettings>()
.BindConfiguration(nameof(TestService));
services.AddSingleton<TestService>();
}
// Configure commands
static partial void ConfigureApp(AppServiceConfig appServiceConfig)
{
// Example: Add a root level command
appServiceConfig
.AddCommand<TestCommand>("test")
.WithDescription("Example test command.")
.WithExample(["test"]);
// Example: Add nested commands using branches
appServiceConfig
.AddBranch(
"yolo",
c => c.AddCommand<TestCommand>("test")
.WithDescription("Example test command.")
.WithExample(["yolo", "test"])
);
// Example: Set application name
appServiceConfig.SetApplicationName("myapp");
}
}
This example demonstrates:
The resulting CLI will support commands like:
myapp test
myapp yolo testYou can customize the build behavior using the following MSBuild properties:
UseDefaultProgram: Set to false to opt out of the default Program.cs file generation. This allows you to provide your own custom Program implementation.
<PropertyGroup>
<UseDefaultProgram>false</UseDefaultProgram>
</PropertyGroup>