Skip to content

Why is AddCommandLine(args) called twice in CreateDefaultBuilder(string[] args)? #26733

Answered by Tratcher
Surbowl asked this question in Q&A
Discussion options

You must be logged in to vote

There are two stages to config. In the first one a few sources are loaded so the host itself can be configured. This is used to read things like ASPNETCORE_ENVIRONMENT, ContentRoot, etc..

if (args != null)
{
builder.UseConfiguration(new ConfigurationBuilder().AddCommandLine(args).Build());
}

Later the host builds a config for the application. It starts with a copy of the host config so the app can re-use those values, and layers everything else on top of that. This is where things like AppSettings.Development.json are added, using the environment and the content root from the host con…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Surbowl
Comment options

@Tratcher
Comment options

@Surbowl
Comment options

Answer selected by Surbowl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants