Skip to content

Environment directives passed to dotnet should only be applied to the target process #40484

@tmat

Description

@tmat

Describe the bug

An environment directive passed to dotnet like so:

dotnet [env:X=Y] run

is currently set to the environment of the dotnet.exe process during parsing of the command line.
The environment variable then automatically flows to all child processes, including MSBuild and VBCSCompiler if dotnet run determines that build is needed.

This is not desirable for multiple reasons:

  • the environment variable might influence the build
  • dotnet-watch needs to set environment variables on the target process to enable Hot Reload (DOTNET_STARTUP_HOOKS, DOTNET_MODIFIABLE_ASSEMBLIES, DOTNET_WATCH_HOTRELOAD_NAMEDPIPE_NAME). If these variables flow into processes for which they are not intended, Hot Reload might break.

Instead, dotnet CLI parser should parse out the variables and then let each command apply them as needed.
For example, dotnet run and dotnet test should set them to the process being launched.

Related:
dotnet/command-line-api#2363
#40035

Further technical details

  • Include the output of dotnet --info
.NET SDK:
 Version:           9.0.100-preview.4.24224.4
 Commit:            fec9bc2d56
 Workload version:  9.0.100-manifests.90bb8117
 MSBuild version:   17.11.0-preview-24222-11+9cdb3615a

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-preview.4.24224.4\

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions