Advertisement
Intermediate ASP.NET Core, Configuration & Options Pattern

How does the command-line configuration provider let you override settings via arguments when running an application, and what's its precedence?

Short answer

The command-line provider (registered by default) parses arguments in --Key=Value or --Key Value format (supporting colon-delimited nested keys) as the highest-precedence configuration source by default, letting you override any setting for a single run without modifying files…

Save ASP.NET Core mock interview
Advertisement
AModel answer
The command-line provider (registered by default) parses arguments in --Key=Value or --Key Value format (supporting colon-delimited nested keys) as the highest-precedence configuration source by default, letting you override any setting for a single run without modifying files or environment variables -- useful for quick local testing or scripted one-off overrides.
dotnet run --ConnectionStrings:DefaultConnection="Server=test;" --Logging:LogLevel:Default=Debug

// Equivalent to setting these keys via any other provider, but only for this single run
Real-world example
A developer debugging a production-like issue locally runs `dotnet run --Logging:LogLevel:Default=Trace` for one session to get maximally verbose logging without permanently changing any configuration file.
Likely follow-ups
  • Does the command-line provider support short-form argument aliases?
  • How does this interact with environment-variable overrides in terms of precedence?
Related topics