diff --git a/dotnet/targets/Microsoft.Sdk.Desktop.targets b/dotnet/targets/Microsoft.Sdk.Desktop.targets index c963d184024f..6b878200c30a 100644 --- a/dotnet/targets/Microsoft.Sdk.Desktop.targets +++ b/dotnet/targets/Microsoft.Sdk.Desktop.targets @@ -15,7 +15,9 @@ <_OpenArguments Condition="'$(StandardInputPath)' != ''">$(_OpenArguments) --stdin "$(StandardInputPath)" <_OpenArgumentsPre Condition="'$(OpenNewInstance)' == 'true'">-n <_OpenArgumentsPre Condition="'$(OpenWaitForExit)' == 'true'">$(_OpenArgumentsPre) -W - <_OpenArguments>$(_OpenArguments) $(RunEnvironment) + <_OpenRunEnvironment>$(RunEnvironment) + <_OpenRunEnvironment>$(_OpenRunEnvironment) @(RuntimeEnvironmentVariable->'--env "%(Identity)=%(Value)"', ' ') + <_OpenArguments>$(_OpenArguments) $(_OpenRunEnvironment) open $(_OpenArgumentsPre) -a "$(TargetDir)/$(_AppBundleName).app" $(OpenArguments) $(_OpenArguments) --args diff --git a/dotnet/targets/Microsoft.Sdk.Mobile.targets b/dotnet/targets/Microsoft.Sdk.Mobile.targets index 0524dea71dfd..7ecf8141a073 100644 --- a/dotnet/targets/Microsoft.Sdk.Mobile.targets +++ b/dotnet/targets/Microsoft.Sdk.Mobile.targets @@ -92,6 +92,7 @@ + diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index 186244756bc7..4df059ea1d25 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -63,6 +63,7 @@ + diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/GetMlaunchArguments.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/GetMlaunchArguments.cs index 5bf54925b1ef..b9008d1a1d19 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/GetMlaunchArguments.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/GetMlaunchArguments.cs @@ -311,8 +311,16 @@ protected string GenerateCommandLineCommands () sb.Add (StandardErrorPath); } - foreach (var envvar in EnvironmentVariables) - sb.Add ("--setenv=" + envvar.ItemSpec); + foreach (var envvar in EnvironmentVariables) { + var hasValue = envvar.MetadataNames.Cast ().Contains ("Value"); + if (hasValue) { + var value = envvar.GetMetadata ("Value"); + sb.Add ("--setenv=" + envvar.ItemSpec + "=" + value); + + } else { + sb.Add ("--setenv=" + envvar.ItemSpec); + } + } sb.Add (WaitForExit ? "--wait-for-exit:true" : "--wait-for-exit:false"); diff --git a/tests/common/DotNet.cs b/tests/common/DotNet.cs index 914cd28c1440..0d0b0de77088 100644 --- a/tests/common/DotNet.cs +++ b/tests/common/DotNet.cs @@ -64,9 +64,10 @@ public static ExecutionResult AssertBuild (string project, Dictionary? properties = null, TimeSpan? timeout = null) + public static ExecutionResult AssertRun (string project, Dictionary? properties = null, TimeSpan? timeout = null, Dictionary? environmentVariables = null) { - return Execute ("run", project, properties, true, timeout: timeout); + var extraArguments = environmentVariables?.SelectMany (kvp => new string [] { "-e", $"{kvp.Key}={kvp.Value}" })?.ToArray () ?? []; + return Execute ("run", project, properties, true, timeout: timeout, extraArguments: extraArguments); } public static ExecutionResult AssertBuildFailure (string project, Dictionary? properties = null) @@ -208,7 +209,7 @@ public static ExecutionResult ExecuteCommand (string exe, Dictionary? properties, bool assert_success = true, string? target = null, bool? msbuildParallelism = null, TimeSpan? timeout = null) + public static ExecutionResult Execute (string verb, string project, Dictionary? properties, bool assert_success = true, string? target = null, bool? msbuildParallelism = null, TimeSpan? timeout = null, params string [] extraArguments) { if (!File.Exists (project)) throw new FileNotFoundException ($"The project file '{project}' does not exist."); @@ -301,6 +302,7 @@ public static ExecutionResult Execute (string verb, string project, Dictionary (); env ["MSBuildSDKsPath"] = null; diff --git a/tests/dotnet/MyRunApp/AppDelegate.cs b/tests/dotnet/MyRunApp/AppDelegate.cs index 36180971144c..2a1b64386bd9 100644 --- a/tests/dotnet/MyRunApp/AppDelegate.cs +++ b/tests/dotnet/MyRunApp/AppDelegate.cs @@ -34,6 +34,12 @@ static int Main (string [] args) } File.WriteAllText (filename, sb.ToString ()); + return 0; + case 2: + foreach (var kvp in Environment.GetEnvironmentVariables ().Cast ().OrderBy (v => v.Key)) { + Console.WriteLine ($"{kvp.Key}={kvp.Value}"); + } + return 0; } diff --git a/tests/dotnet/UnitTests/ProjectTest.cs b/tests/dotnet/UnitTests/ProjectTest.cs index 5985fd1691e3..c8808efce964 100644 --- a/tests/dotnet/UnitTests/ProjectTest.cs +++ b/tests/dotnet/UnitTests/ProjectTest.cs @@ -3853,9 +3853,11 @@ public void HttpClientHandlerFeatureTrimmedAway (ApplePlatform platform, string } } - [TestCase (ApplePlatform.MacCatalyst)] - [TestCase (ApplePlatform.MacOSX)] - public void Run (ApplePlatform platform) + [TestCase (ApplePlatform.MacCatalyst, true)] + [TestCase (ApplePlatform.MacCatalyst, false)] + [TestCase (ApplePlatform.MacOSX, true)] + [TestCase (ApplePlatform.MacOSX, false)] + public void Run (ApplePlatform platform, bool dotnetRunEnvironmentSupport) { var project = "MyRunApp"; Configuration.IgnoreIfIgnoredPlatform (platform); @@ -3869,6 +3871,7 @@ public void Run (ApplePlatform platform) var stderr = Path.Combine (tmpdir, "stderr.txt"); var properties = GetDefaultProperties (); + var dotnetRunEnvironment = new Dictionary (); properties ["XamarinDebugMode"] = "telegraph"; properties ["XamarinDebugHosts"] = "localhost"; properties ["XamarinDebugPort"] = "123"; @@ -3876,8 +3879,14 @@ public void Run (ApplePlatform platform) properties ["StandardErrorPath"] = stderr; properties ["OpenNewInstance"] = "true"; properties ["OpenWaitForExit"] = "true"; - properties ["RunEnvironment"] = $"--env TEST_CASE=1 --env VARIABLE=VALUE --env TEST_FILENAME={tmpfile}"; - DotNet.AssertRun (project_path, properties); + if (dotnetRunEnvironmentSupport) { + properties ["RunEnvironment"] = $"--env TEST_CASE=1 --env VARIABLE=VALUE --env TEST_FILENAME={tmpfile}"; + } else { + dotnetRunEnvironment ["TEST_CASE"] = "1"; + dotnetRunEnvironment ["VARIABLE"] = "VALUE"; + dotnetRunEnvironment ["TEST_FILENAME"] = tmpfile; + } + DotNet.AssertRun (project_path, properties, environmentVariables: dotnetRunEnvironment); Assert.Multiple (() => { var envContents = File.ReadAllText (tmpfile);