Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dotnet/targets/Microsoft.Sdk.Desktop.targets
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<_OpenArguments Condition="'$(StandardInputPath)' != ''">$(_OpenArguments) --stdin "$(StandardInputPath)"</_OpenArguments>
<_OpenArgumentsPre Condition="'$(OpenNewInstance)' == 'true'">-n </_OpenArgumentsPre>
<_OpenArgumentsPre Condition="'$(OpenWaitForExit)' == 'true'">$(_OpenArgumentsPre) -W </_OpenArgumentsPre>
<_OpenArguments>$(_OpenArguments) $(RunEnvironment)</_OpenArguments>
<_OpenRunEnvironment>$(RunEnvironment)</_OpenRunEnvironment>
<_OpenRunEnvironment>$(_OpenRunEnvironment) @(RuntimeEnvironmentVariable->'--env "%(Identity)=%(Value)"', ' ')</_OpenRunEnvironment>
<_OpenArguments>$(_OpenArguments) $(_OpenRunEnvironment)</_OpenArguments>
<RunCommand>open</RunCommand>
<RunArguments>$(_OpenArgumentsPre) -a "$(TargetDir)/$(_AppBundleName).app" $(OpenArguments) $(_OpenArguments) --args</RunArguments>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions dotnet/targets/Microsoft.Sdk.Mobile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<!-- don't set standard output/error path, mlaunch will by default write to stdout/stderr -->
</PropertyGroup>
<ItemGroup>
<MlaunchEnvironmentVariables Include="@(RuntimeEnvironmentVariable)" />
<MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_MODE__=$(XamarinDebugMode)" Condition="'$(XamarinDebugMode)' != ''" />
<MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_PORT__=$(XamarinDebugPort)" Condition="'$(XamarinDebugPort)' != ''" />
<MlaunchEnvironmentVariables Include="__XAMARIN_DEBUG_HOSTS__=$(XamarinDebugHosts.Replace(';', '%3B'))" Condition="'$(XamarinDebugHosts)' != ''" />
Expand Down
1 change: 1 addition & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<ItemGroup>
<ProjectCapability Include="Apple" />
<ProjectCapability Include="Mobile" />
<ProjectCapability Include="RuntimeEnvironmentVariableSupport" />

<ProjectCapability Include="IOSApplication" Condition="'$(_ProjectType)' == 'iOSExecutableProject'" />
<ProjectCapability Include="IOSAppExtension" Condition="'$(_ProjectType)' == 'iOSAppExtensionProject'" />
Expand Down
12 changes: 10 additions & 2 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/GetMlaunchArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> ().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");

Expand Down
8 changes: 5 additions & 3 deletions tests/common/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ public static ExecutionResult AssertBuild (string project, Dictionary<string, st
return Execute ("build", project, properties, true, target: target, timeout: timeout);
}

public static ExecutionResult AssertRun (string project, Dictionary<string, string>? properties = null, TimeSpan? timeout = null)
public static ExecutionResult AssertRun (string project, Dictionary<string, string>? properties = null, TimeSpan? timeout = null, Dictionary<string, string>? 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<string, string>? properties = null)
Expand Down Expand Up @@ -208,7 +209,7 @@ public static ExecutionResult ExecuteCommand (string exe, Dictionary<string, str
return new ExecutionResult (output, output, rv.ExitCode);
}

public static ExecutionResult Execute (string verb, string project, Dictionary<string, string>? properties, bool assert_success = true, string? target = null, bool? msbuildParallelism = null, TimeSpan? timeout = null)
public static ExecutionResult Execute (string verb, string project, Dictionary<string, string>? 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.");
Expand Down Expand Up @@ -301,6 +302,7 @@ public static ExecutionResult Execute (string verb, string project, Dictionary<s
args.Add ("-maxcpucount:1");
}
}
args.AddRange (extraArguments);

var env = new Dictionary<string, string?> ();
env ["MSBuildSDKsPath"] = null;
Expand Down
6 changes: 6 additions & 0 deletions tests/dotnet/MyRunApp/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DictionaryEntry> ().OrderBy (v => v.Key)) {
Console.WriteLine ($"{kvp.Key}={kvp.Value}");
}

return 0;
}

Expand Down
19 changes: 14 additions & 5 deletions tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -3869,15 +3871,22 @@ public void Run (ApplePlatform platform)
var stderr = Path.Combine (tmpdir, "stderr.txt");

var properties = GetDefaultProperties ();
var dotnetRunEnvironment = new Dictionary<string, string> ();
properties ["XamarinDebugMode"] = "telegraph";
properties ["XamarinDebugHosts"] = "localhost";
properties ["XamarinDebugPort"] = "123";
properties ["StandardOutputPath"] = stdout;
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);
Expand Down
Loading