ASP.NET Core Interview Question #46
How can command-line arguments configure an ASP.NET Core application?
Application Structure & Configuration Junior Beginner
Quick Interview Answer
Command-line arguments are added to configuration by the default host configuration created with WebApplication.CreateBuilder(args).
Detailed Explanation
Command-line arguments are added to configuration by the default host configuration created with WebApplication.CreateBuilder(args).
They can override settings supplied by earlier configuration providers. This is useful for deployments, scripts, or temporary runtime configuration where a setting needs to be supplied when the process starts.
Command-line configuration should be used carefully for sensitive values because command lines may be visible through operating-system process inspection or deployment logs.
Code Example
// Start application:
// dotnet MyApp.dll --Reports:PageSize=100
var pageSize =
builder.Configuration.GetValue<int>("Reports:PageSize");