1

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.