> For the complete documentation index, see [llms.txt](https://plutolabs.gitbook.io/plutoframework/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://plutolabs.gitbook.io/plutoframework/make-your-application/environment-variables.md).

# 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");
```
