"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"SQLServer":
{
"Host":"sql123",
"Port":"1433"
}
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment;
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json",
optional: true, reloadOnChange: true);
config.AddEnvironmentVariables();
})
.UseStartup<Startup>();
var setting=config.GetValue<string>("SQLServer:Host");
override through environment variable
PS> $env:SQLServer__Host="test"
dotnet run
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\netcoreenvtest.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" >
<environmentVariables>
<environmentVariable name="SQLServer__Host" value="PUNKISDEAD" />
</environmentVariables>
<aspNetCore/>
</system.webServer>
</configuration>