L_7337
L_7337

Reputation: 2738

ASP.NET Core Environment Variable Not Set

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

Answers (1)

L_7337
L_7337

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: Project properties

These are NOT coming from your Windows System Environment Variables in Advanced System Settings.

Upvotes: 2

Related Questions