In this Azure tutorial, we will discuss how to fix the error. Configurationbuilder does not contain a definition for addenvironmentvariables. I got it while working with the Azure function to access the app settings using Visual Studio.
Table of Contents
Addenvironmentvariables not found
I was working with the Azure Functions and was trying to access application settings using Visual Studio, but I got the error.
The Azure function was like below
public static class MyProductHTTPFunction
{
[FunctionName("MyProductHTTPFunction")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log, ExecutionContext context)
{
log.LogInformation("MyProductHTTPFunction function processed a request.");
var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
string myappsettingsValue = configurationBuilder["appsettingkey"];You can see here

The exact error message was as below
Error CS1061 ‘IConfigurationBuilder’ does not contain a definition for ‘AddEnvironmentVariables’ and no accessible extension method ‘AddEnvironmentVariables’ accepting a first argument of type ‘IConfigurationBuilder’ could be found (are you missing a using directive or an assembly reference?)
Addenvironmentvariables not found [Solved]
To fix this error, we need to add a few NuGet Packages. To do that, follow the below steps
1. Right-click on the Project and click on the Manage NuGet Packages

2. You need to add the Microsoft.Extensions.Configuration.EnvironmentVariables package like below. Search for the same package and click on the Install button.

In the same way, you can add the Nuget package Microsoft.Extensions.Configuration.UserSecrets.

The above are the two packages you need to install if you are getting the error due to AddEnvironmentVariables().
There is a chance you might get the same error for the SetBasePath() method. In that case, you need to add one Nuget package in the same way as above i.e Microsoft.Extensions.Configuration.Abstractions.

This will fix the issue of the SetBasePath() method.
Also, You might get the same error for the AddJsonFile() method. To fix the issue, you need to install two Microsoft Nuget Packages.Extensions.Configuration.FileExtensions and Microsoft.Extensions.Configuration.Json.

Also, the package below

You may also like following the below Articles
- No match was found for the specified search criteria and module names ‘AzTable’
- CS1061 C# ‘HttpRequest’ does not contain a definition for ‘Content’ and no accessible extension method ‘Content’ accepting a first argument of type ‘HttpRequest’ could be found
- The Term ‘Connect-AzureRmAccount’ is Not Recognized
- The term ‘Select-AzureSubscription’ is not recognized as the name of a cmdlet
Wrapping Up
In this article, we have discussed how to fix the error configurationbuilder addenvironmentvariables not found. The above solution will also fix the issues
I hope it will help you to fix your issue !!!
I am Bijay, a Microsoft MVP (10 times) having more than 17 years of experience in the software industry. During my IT career, I got a chance to share my expertise in SharePoint and Microsoft Azure, like Azure VM, Azure Active Directory, Azure PowerShell, etc. I hope you will learn from these Azure tutorials. Read more
