Skip to content

Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") does not return the environment variable's value entered in the CLI #100674

@Arash-Sabet

Description

@Arash-Sabet

Description

We have a dotnet 8.0 console application that is supposed to read an appsettings.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT")}.json file based on the value entered for the DOTNET_ENVIRONMENT environment variable. Unfortunately Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") always returns null.

Reproduction Steps

Issue the following command:

 dotnet run -c Release -e DOTNET_ENVIRONMENT=Docker

Expected behavior

Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") should return the value Docker per the reproduction step to be able to utilize appsettings.Docker.json file.

Actual behavior

Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") returns null or empty.

Regression?

No response

Known Workarounds

No response

Configuration

.NET SDK:
Version: 8.0.203
Commit: 5e1ceea679
Workload version: 8.0.200-manifests.8cf8de6d

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.203\

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-HostquestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions