PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 21, 2022

[FIXED] How to Pull Docker Environment Variables from launchSettings.json in C#

 August 21, 2022     c#, docker, environment-variables     No comments   

Issue

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"
      }
    }
  }
}

Solution

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.

Build

That will ensure it's pointing to the right profile and it will then pull your environment variables as you have defined.



Answered By - Skin
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing