microsoft / microsoft/aspire

Support `.env` within the `WithEnvironment` API.

Open
#10,150 4 comments 7 reactions 0 assignees View on GitHub
area-app-model
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

## Background and Motivation

Add support for passing an `.env` path to the `.WithEnvironment` API.

## Proposed API

```cs
public static class ResourceBuilderExtensions
{
private const string ConnectionStringEnvironmentName = "ConnectionStrings__";

///
/// Adds an environment variable to the resource.
///
/// The resource type.
/// The resource builder.
/// The path to the .env file.
/// The .
public static IResourceBuilder WithEnvironment(this IResourceBuilder builder, string dotEnvPath) where T : IResourceWithEnvironment
{
// Implementation details...
}

// Existing APIs...
}
```

## Usage Examples

```cs
var builder = DistributedApplication.CreateBuilder(args);

var api = builder.AddProject("api")
.WithEnvironment("../../api/.env");

builder.Build().Run();
```

## Alternative Designs

It would be nice if the extensions libraries supported .env, I know that it's been requested for a long time now: https://github.com/dotnet/runtime/issues/49667. If this support was added natively as a configuration provider, then it might be easier to pull these values in to map to the resource's env vars.

## Risks

N/A

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.