microsoft / microsoft/aspire

Docker Compose publisher does not preserve colon-delimited entries in existing .env files

Open Beginner friendly
#18,775 0 comments 0 reactions 0 assignees View on GitHub
area-deployment
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

While reviewing the Docker Compose environment-file implementation, I found
that valid colon-delimited entries are not recognized when an existing `.env`
file is loaded and rewritten.

Docker Compose supports both of the following forms:

```env
EQUALS_DELIMITED_VALUE=preserve-equals
COLON_DELIMITED_VALUE: preserve-colon

### Expected Behavior

```markdown
When Aspire loads and updates an existing Docker Compose `.env` file, it should
preserve valid entries that use either supported key-value delimiter:

```env
EQUALS_DELIMITED_VALUE=preserve-equals
COLON_DELIMITED_VALUE: preserve-colon

### Steps To Reproduce

```markdown
The behavior can be reproduced directly against the current `EnvFile`
implementation with a temporary environment file.

1. Create a temporary `.env` file containing:

```env
EQUALS_DELIMITED_VALUE=preserve-equals
COLON_DELIMITED_VALUE: preserve-colon

### Exceptions (if any)

```markdown
No exception is expected.

The concern is that the file rewrite completes normally while the
colon-delimited entry is omitted. This makes the behavior potentially silent
rather than producing an obvious failure.

### Aspire doctor output

Not applicable for this source-level report.

The issue concerns the parsing and serialization behavior in
`src/Aspire.Hosting.Docker/EnvFile.cs` on the repository's current `main`
branch rather than a failure caused by a particular local Aspire installation.

I can provide environment-specific `aspire doctor` output if the maintainers
require a full end-to-end Docker Compose publisher reproduction.

### Anything else?

### Relevant implementation

The behavior appears to originate in:

```text
src/Aspire.Hosting.Docker/EnvFile.cs

if (!trimmed.StartsWith('#') && trimmed.Contains('='))
{
var eqIndex = trimmed.IndexOf('=');
// ...
}

foreach (var entry in Entries.Values)
{
lines.Add(
entry.Value is not null
? $"{entry.Key}={entry.Value}"
: $"{entry.Key}=");
}

Contributor guide

Open the contributing guide

Research direction

Start with src/Aspire.Hosting.Docker/EnvFile.cs, especially the parsing condition and rewrite loop shown in the issue. Reproduce the behavior using a temporary .env file containing both equals- and colon-delimited entries, then verify that loading and rewriting preserves both entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, docker-compose
Domain
devops
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.