I have a launchSettings.json file and some Docker environmentVariables. I attempted to pull one of the settings using GetEnvironmentVariable, and it doesn't seem to be working.
string strTest = Environment.GetEnvironmentVariable("TESTING");
Console.WriteLine($"Docker Env Test: {strTest}");
It isn't returning anything. I've searched around and the GetEnvironmentVariable seems to be the way to do it, but it's only returning variables from ProgC.
launchSettings.json
{
"profiles": {
"ProgC": {
"commandName": "Project",
"environmentVariables": {
"IsDev": "1",
"JobName": "ProgC",
"Environment": "TEST"
}
},
"Docker": {
"commandName": "Docker",
"environmentVariables": {
"IsDev": "1",
"JobName": "ProgC",
"AppID": "372011",
"ConfigurationID": "1",
"Environment": "TEST",
"TESTING": " Yup"
}
}
}
}
CodePudding user response:
I'm going to make the assumption that you're doing this from within Visual Studio.
You need to make sure you're selecting the correct build properties when you run/publish your app. I'm also going to assume that at present, ProgC
is selected and needs to be changed.
That will ensure it's pointing to the right profile and it will then pull your environment variables as you have defined.
CodePudding user response:
launchsettings.json is an abomination designed to confuse people.
They simply aren't used when you run in Docker. They're only used when you run from Visual Studio, Rider or another IDE, that supports it.