diff --git a/src/Tasks.UnitTests/Exec_Tests.cs b/src/Tasks.UnitTests/Exec_Tests.cs index e28b770d85e..088e68c81b0 100644 --- a/src/Tasks.UnitTests/Exec_Tests.cs +++ b/src/Tasks.UnitTests/Exec_Tests.cs @@ -69,6 +69,42 @@ public void EscapeSpecifiedCharactersInPathToGeneratedBatchFile() } } + [UnixOnlyTheory] + [InlineData(true)] + [InlineData(false)] + public void ExecSetsLocaleOnUnix(bool enableChangeWave) + { + using (var env = TestEnvironment.Create()) + { + env.SetEnvironmentVariable("LANG", null); + env.SetEnvironmentVariable("LC_ALL", null); + + if (enableChangeWave) + { + ChangeWaves.ResetStateForTests(); + // Important: use the version here + env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", ChangeWaves.Wave17_10.ToString()); + BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); + } + + Exec exec = PrepareExec("echo LANG=$LANG; echo LC_ALL=$LC_ALL;"); + bool result = exec.Execute(); + Assert.True(result); + + MockEngine engine = (MockEngine)exec.BuildEngine; + if (enableChangeWave) + { + engine.AssertLogContains("LANG=en_US.UTF-8"); + engine.AssertLogContains("LC_ALL=en_US.UTF-8"); + } + else + { + engine.AssertLogDoesntContain("LANG=en_US.UTF-8"); + engine.AssertLogDoesntContain("LC_ALL=en_US.UTF-8"); + } + } + } + /// /// Ensures that calling the Exec task does not leave any extra TEMP files /// lying around. diff --git a/src/Tasks/Exec.cs b/src/Tasks/Exec.cs index dbf4be1fc51..9faaa688874 100644 --- a/src/Tasks/Exec.cs +++ b/src/Tasks/Exec.cs @@ -591,7 +591,12 @@ protected internal override void AddCommandLineCommands(CommandLineBuilderExtens { commandLine.AppendSwitch("-c"); commandLine.AppendTextUnquoted(" \""); - commandLine.AppendTextUnquoted("export LANG=en_US.UTF-8; export LC_ALL=en_US.UTF-8; . "); + bool setLocale = !ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_10); + if (setLocale) + { + commandLine.AppendTextUnquoted("export LANG=en_US.UTF-8; export LC_ALL=en_US.UTF-8; "); + } + commandLine.AppendTextUnquoted(". "); commandLine.AppendFileNameIfNotNull(batchFileForCommandLine); commandLine.AppendTextUnquoted("\""); }