When there are no environment variables set, you get every environment variable on your local machine
- 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
When running an Aspire app (Mac/VSCode) without any env vars specified, the dashboard loads in all my env vars from the system:
```
var builder = DistributedApplication.CreateBuilder(args);
builder.AddPythonProject("python-app", "../python-app/", "myteam.py");
builder.Build().Run();
```

When I specify anything - env: PORT, WithEnvironment() (in this case, with dotnet user-secrets) none of my env vars load in except for the specified ones (which is the expected behavior I think):
```
var py = builder.AddPythonProject("python-app", "../python-app/", "myteam.py")
.WithHttpEndpoint(env: "FLASK_RUN_PORT")
.WithEnvironment("ESPN_S2", builder.Configuration["ESPN_S2"])
.WithEnvironment("SWID", builder.Configuration["SWID"]);
```

I feel like it's weird to load in all my env vars by default if nothing is specified?! What I _think_ might be happening is that since dotnet and node apps get a bunch of OTEL env vars loaded in by default, we don't notice this bug in most cases, but since Python doesn't load any (unless you specify) it just sucks in my entire environment. (Sidebar we should probably make OTEL the default in python too I'll file another bug later)
### Expected Behavior
When no environment variables are specified, none of my local machine's environment variables are visible in the dashboard.
### Steps To Reproduce
```
var py = builder.AddPythonProject("python-app", "../python-app/", "myapp.py")
```
this shows every system environment variable in the dashboard.
```
var py = builder.AddPythonProject("python-app", "../python-app/", "myapp.py")
.WithHttpEndpoint(env: "PORT")
```
This only shows the "PORT" env var in the dashboard.
### Exceptions (if any)
_No response_
### .NET Version info
dotnet --info
.NET SDK:
Version: 8.0.301
Commit: 1a0e9c0300
Workload version: 8.0.300-manifests.d7126b9e
MSBuild version: 17.10.4+10fbfbf2e
Runtime Environment:
OS Name: Mac OS X
OS Version: 14.5
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/8.0.301/
.NET workloads installed:
[maui-tizen]
Installation Source: SDK 8.0.300
Manifest Version: 8.0.61/8.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.maui/8.0.61/WorkloadManifest.json
Install Type: FileBased
[maui-maccatalyst]
Installation Source: SDK 8.0.300
Manifest Version: 8.0.61/8.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.maui/8.0.61/WorkloadManifest.json
Install Type: FileBased
[maui-ios]
Installation Source: SDK 8.0.300
Manifest Version: 8.0.61/8.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.maui/8.0.61/WorkloadManifest.json
Install Type: FileBased
[maui-android]
Installation Source: SDK 8.0.300
Manifest Version: 8.0.61/8.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.maui/8.0.61/WorkloadManifest.json
Install Type: FileBased
[aspire]
Installation Source: SDK 8.0.300
Manifest Version: 8.1.0/8.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.aspire/8.1.0/WorkloadManifest.json
Install Type: FileBased
[maui]
Installation Source: SDK 8.0.300
Manifest Version: 8.0.61/8.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.maui/8.0.61/WorkloadManifest.json
Install Type: FileBased
Host:
Version: 8.0.6
Architecture: arm64
Commit: 3b8b000a0e
.NET SDKs installed:
8.0.100-rc.2.23502.2 [/usr/local/share/dotnet/sdk]
8.0.301 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.0-rc.2.23480.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.0-rc.2.23479.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
### Anything else?
_No response_
Contributor guide
Research direction
Start with the AddPythonProject entry point and the WithEnvironment/WithHttpEndpoint behavior described in the issue. Run both reproduction snippets and trace how environment variables are passed to the Python resource and shown in the dashboard; done means an unspecified environment produces no local machine variables, while explicitly specified variables remain visible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100