Reputation: 2738
I'm trying to use Environment variables in my application so I don't have to bother maintaining config files across different systems. Maybe I just have a misunderstanding about where these variables are coming from.
First, I created a Windows System variable called MediatrExampleDbConnection
on my local System -> Advanced properties
Then, I have this code in my Startup.cs :
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
When I try to access it later, it comes back null :
var MediatrConnectionString = Configuration["MediatrExampleDbConnection"];
Isn't this supposed to pull from my local System variables since I have .AddEnvironmentVariables();
in there?
Upvotes: 1
Views: 2554
Reputation: 2738
Ok, my misunderstanding.
According to this post: Accessing environment variables from ASP.NET Core 1 RC1 IConfiguration
These are Web Application, Environment Variables from your Project properties:
These are NOT coming from your Windows System Environment Variables in Advanced System Settings.
Upvotes: 2