I'm trying to get double underscore for configurations to work in ASP.Net core 3.1 as described here: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?tabs=basicconfiguration&view=aspnetcore-3.1#environment-variables
I've written some code for configurations that does this manually
- check Env Var
- check AppSettings...json files
but I saw that in .net 3.1 this is supposed to be supported by default with one caveat around hierarchal settings on unix platforms. In this case you can't use this syntax
Configuration["SomeSection:SomeConfig"]
to resolve this environment variable
## Environment Var
SomeConfig:SomeConfig
Because linux doesn't support colons in Env Var names. This would however work if code was deployed to a windows machine. So instead .net seems to indicate you can use this syntax
Configuration["SomeSection__SomeConfig"]
which will resolve any of the following configurations
// AppSettings...json
{
"SomeSection" {
"SomeConfig": "some value"
}
}
or
# Environment Var on linux
SomeConfig__SomeConfig
or
// Environment Var on windows
SomeConfig:SomeConfig
Does anyone know what I'm doing wrong?
Edit: Note that I know the answer to this questions and will happily answer it if it's is reopened.
Configuration["SomeSection:SomeConfig"]
doesn't access an environment variable, it retrieves theSomeConfig
setting from theSomeSection
section, no matter where this comes from. The values are provided by config providers that may load the settings from files, databases, the command line, services etc. So what you seem to ask is only how the environment variable provider works in Linux and how env variable names are mapped to configuration settings – Panagiotis KanavosSomeSection__SomeConfig
should work on all platforms – Panagiotis Kanavos