dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.65k stars 1.06k forks source link

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

Open tmat opened 4 months ago

tmat commented 4 months ago

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:

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: https://github.com/dotnet/command-line-api/issues/2363 https://github.com/dotnet/sdk/issues/40035

Further technical details

.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\
tmat commented 4 months ago

@baronfel @jonsequitur @KathleenDollard