Skip to content

Instantly share code, notes, and snippets.

@jwatney
Created June 5, 2019 23:27
Show Gist options
  • Save jwatney/b7bdfd124f299d5e616716ec700951cf to your computer and use it in GitHub Desktop.
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.
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);
}
}
}
}
}
}
@jwatney
Copy link
Author

jwatney commented Jun 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment