Install these packages:
Code:
static void Main(string[] args)
{
var environmentName = Environment.GetEnvironmentVariable("ENVIRONMENT");
Console.WriteLine("ENVIRONMENT: " + environmentName);
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false)
.AddJsonFile($"appsettings.{environmentName}.json", true)
.AddEnvironmentVariables();
IConfigurationRoot configuration = builder.Build();
var mySettingsConfig = configuration.Get<MySettingsConfig>();
Console.WriteLine("URL: " + mySettingsConfig.Url);
Console.WriteLine("NAME: " + mySettingsConfig.Name);
Console.ReadKey();
}
MySettingsConfig Class:
public class MySettingsConfig
{
public string Url { get; set; }
public string Name { get; set; }
}