Rob Kraft's Software Development Blog

Software Development Insights

How to Emulate Azure Function Application Settings Read Via Environment.GetEnvironmentVariable on Local Machine

Posted by robkraft on March 25, 2020

I borrowed a bit of code from an existing .Net Framework app that I had used to write an Azure function years ago.  But my new app was based on .Net Core and the code to retrieve an Environment variable (Environment.GetEnvironmentVariable) did not pull a value out of my .json file.

It took me a little googling around to figure out how to make it work so I figured I might as well share my findings in a blog post.  It will probably help “Future Rob” fix the problem more quickly if no one else.

If you have code like the following that pulls values from the “Application Settings” in an Azure function:

data[“refresh_token”] = Environment.GetEnvironmentVariable(“refresh_token”);
data[“grant_type”] = “refresh_token”;
data[“client_id”] = Environment.GetEnvironmentVariable(“client_id”);
data[“client_secret”] = Environment.GetEnvironmentVariable(“client_secret”);

but you want to run that code on your local machine, you just need to put your values inside the “Values” node of local.settings.json as shown here:

"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"client_id": "xxx",
"client_secret": "yyy",
"refresh_token": "zzz"


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: