Created
June 5, 2019 23:27
-
-
Save jwatney/b7bdfd124f299d5e616716ec700951cf to your computer and use it in GitHub Desktop.
Call this at the top of Application_Start. Any key/value pairs (delimited by '=') will be loaded into the processes environment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class EnvironmentVariables { | |
public static void SetUp() { | |
var configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "Environment.config"); | |
if(File.Exists(configFile)) { | |
var lines = File.ReadAllLines(configFile); | |
foreach(var line in lines) { | |
var index = line.IndexOf("=", StringComparison.Ordinal); | |
if(index > -1) { | |
var key = line.Substring(0, index); | |
if(key.Trim() != "") { | |
var value = line.Substring(index + 1); | |
Environment.SetEnvironmentVariable(key, value, EnvironmentVariableTarget.Process); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See: https://gist.github.com/jwatney/c00ac732f2d3ebec58801e7ff17a8408