I have the following code in my Program.cs:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(b => b
.AddEnvironmentVariables()
.AddMyCustomConfiguration(o => o.UseSqlServer(
Environment.GetEnvironmentVariable("ConnectionStrings:MyDatabase"))))
.UseStartup<Startup>();
My appsettings.json
looks like this:
{
"ConnectionStrings": {
"MyDatabase": "connectionstring"
}
}
However, Environment.GetEnvironmentVariable("ConnectionStrings:MyDatabase")
is returning null. I was under the impression that AddEnvironmentVariables
would load the necassary variables. Is this not the case / how can I get this to load the connection string?