runtime: Environment.GetEnvironmentVariables() should tolerate duplicate case-insensitive variable names

Description

Some tools like Yarn will spawn nodeJS via CreateProcess and pass an environment block that contains duplicated environment variables, e.g: image

Windows doesn’t do any checking of environment variables being duplicated in CreateProcess so the node.exe process gets created with the two names. Then in our case, MSBuild (a .net app) gets launched from within node.exe, which later launches CL.exe and other build tools, which break because they don’t expect to get the same variable twice in the env block.

The environment block as exposed in Process should be cleaned up to remove duplicates (i.e. variables that appear more than once)

Configuration

Windows 10, all .net versions, all archs.

Regression?

Other information

Related bugs: https://github.com/actions/virtual-environments/pull/1566 https://github.com/nodejs/node/issues/35129 https://github.com/dotnet/msbuild/issues/5726

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@asklar the bar for taking changes to .NET Framework is very high – it is also a lengthy and costly process. I do not think this would be successful. I recommend a fix to Yarn, or how it’s configured, or a wrapper script that fixes the environment block, or perhaps continue the discussion with MSBuild (as it ships in the SDK which is easier to change - I am not offering an opinion on whether the change is right for MSBuild).