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.
.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\
Describe the bug
An environment directive passed to dotnet like so:
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, includingMSBuild
andVBCSCompiler
ifdotnet run
determines that build is needed.This is not desirable for multiple reasons:
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
anddotnet 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
dotnet --info