No.1 添加所需要的dll
Microsoft.Extensions.Configuration.EnvironmentVariables
No.2 代码实现
代码语言:javascript复制 IConfiguration configuration = new ConfigurationBuilder()
.SetBasePath(Environment.CurrentDirectory)
.AddEnvironmentVariables()
.Build();
var java_home = configuration["JAVA_HOME"];
Console.WriteLine(java_home);
Console.ReadKey();
这里我以读取JAVA_HOME环境变量为例,下面是输出结果