'Load host IConfiguration from supplied command line args;
ASP.NET Core apps configure and launch a host. The host is responsible for app startup and lifetime management by auto-generating a “Program.cs”, which takes care of setting up a host. According to the documentation, if you use CreateDefaultBuilder, the following defaults are applied to HostBuilder:
- load host IConfiguration from supplied command line args;
- load app IConfiguration from environment variables;
Does anyone have information on how the arguments affect the CreateDefaultBuilder? If I pass arguments on the following code, How can I access that?
static void Main(string[] args) { IHostBuilder common= Host.CreateDefaultBuilder(args) }
Solution 1:[1]
I just found out how to use IConfiguration. If you Inject "foo:123" on the arguments, you could store it this way:
IConfiguration Configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.AddCommandLine(args)
.Build();
var customSection = Configuration.GetSection("foo");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | André |
