# Environment variables

{% hint style="success" %}
Up to date
{% endhint %}

To set environment variables go to `PlutoFramework/appsettings.json` file (if the file does not exist, create it) and fill in the contents like this:

```json
{
    "VARIABLE_NAME_1": "value 1",
    "VARIABLE_NAME_2": "value 2"
}
```

These environment variables then need to be loaded in `PlutoFramework/MauiProgram.cs` using the `AddAppSettings` method. Add it to your code:

```csharp
public static MauiAppBuilder AddAppSettings(this MauiAppBuilder builder)
{
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
    using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"{nameof(YourAppNamespace)}.appsettings.json");
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.

    if (stream is null)
    {
        return builder;
    }

    IConfigurationRoot configuration = new ConfigurationBuilder()
        .AddJsonStream(stream)
        .Build();

    builder.Configuration.AddConfiguration(configuration);

    return builder;
}
```

```csharp
var builder = MauiApp.CreateBuilder();
builder
    .UseMauiApp<App>()
    .UseMauiCommunityToolkit()
    .UsePlutoFramework()
    .AddAppSettings(); // Add this line

var app = builder.Build();
```

You can then access the environment variable like this:

```csharp
var configuration = MauiProgram.Services.GetService<IConfiguration>();

var value1 = configuration.GetValue<string>("VARIABLE_NAME_1");
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://plutolabs.gitbook.io/plutoframework/make-your-application/environment-variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
