Skip to content

Commit

Permalink
Setting an environment variable to null doesn't work in .netcore. (#8316
Browse files Browse the repository at this point in the history
)

There is a difference between mono and .netcore with regards to environment
variables when launching processes.

For the following example:

    process.StartInfo.EnvironmentVariables ["FOO"] = null;

.netcore will launch the process with an empty FOO variable, while mono will
launch the process with no FOO variable set.

So unstead remove the variable from the collection of environment variables
(this works fine even if the collection doesn't contain the variable).

Ref: dotnet/runtime#34446
  • Loading branch information
rolfbjarne authored and mandel-macaque committed Oct 5, 2020
1 parent 222989d commit 10063ea
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
9 changes: 7 additions & 2 deletions tests/xharness/Jenkins/TestTasks/AppleTestTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ protected override void SetEnvironmentVariables (Process process)
throw new NotImplementedException ();
}

foreach (var kvp in Environment)
process.StartInfo.EnvironmentVariables [kvp.Key] = kvp.Value;
foreach (var kvp in Environment) {
if (kvp.Value == null) {
process.StartInfo.EnvironmentVariables.Remove (kvp.Key);
} else {
process.StartInfo.EnvironmentVariables [kvp.Key] = kvp.Value;
}
}
}


Expand Down
2 changes: 1 addition & 1 deletion tests/xharness/Jenkins/TestTasks/MSBuildTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override async Task ExecuteAsync ()
xbuild.StartInfo.FileName = ToolName;
xbuild.StartInfo.Arguments = StringUtils.FormatArguments (ToolArguments);
SetEnvironmentVariables (xbuild);
xbuild.StartInfo.EnvironmentVariables ["MSBuildExtensionsPath"] = null;
xbuild.StartInfo.EnvironmentVariables.Remove ("MSBuildExtensionsPath");
LogEvent (BuildLog, "Building {0} ({1})", TestName, Mode);
if (!Harness.DryRun) {
var timeout = TimeSpan.FromMinutes (60);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,13 @@ static async Task<ProcessExecutionResult> RunAsyncInternal (Process process,
process.StartInfo.UseShellExecute = false;

if (environmentVariables != null) {
foreach (var kvp in environmentVariables)
process.StartInfo.EnvironmentVariables [kvp.Key] = kvp.Value;
foreach (var kvp in environmentVariables) {
if (kvp.Value == null) {
process.StartInfo.EnvironmentVariables.Remove (kvp.Key);
} else {
process.StartInfo.EnvironmentVariables [kvp.Key] = kvp.Value;
}
}
}

process.OutputDataReceived += (sender, e) => {
Expand Down
2 changes: 1 addition & 1 deletion tools/mtouch/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public void CreateAOTTask (Abi abi)
// Visual Studio for Mac sets this environment variable, and it confuses the AOT compiler.
// So unset it.
// See https://github.com/mono/mono/issues/11765
task.ProcessStartInfo.EnvironmentVariables ["MONO_THREADS_SUSPEND"] = null;
task.ProcessStartInfo.EnvironmentVariables.Remove ("MONO_THREADS_SUSPEND");
}

aotInfo.Task = task;
Expand Down

0 comments on commit 10063ea

Please sign in to comment.