Skip to content
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
<Uri>https://github.com/dotnet/dotnet</Uri>
<Sha>73b3b5ac0e4a5658c7a0555b67d91a22ad39de4b</Sha>
</Dependency>
<Dependency Name="Xamarin.Apple.Tools.MaciOS" Version="1.0.0-preview.1.26201.1">
<Dependency Name="Xamarin.Apple.Tools.MaciOS" Version="1.0.0-preview.1.26228.1">
<Uri>https://github.com/dotnet/macios-devtools</Uri>
<Sha>14efcb9735fab369066fa3c99130d076aa0dfdc9</Sha>
<Sha>0c544e8cf5ed4ba7ce7c7cc10802a365fd9ace30</Sha>
</Dependency>
</ProductDependencies>
<ToolsetDependencies>
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</PropertyGroup>
<!-- Apple platform tooling (managed via darc/maestro — see eng/Version.Details.xml) -->
<PropertyGroup Label="Apple Tools">
<XamarinAppleToolsMaciOSVersion>1.0.0-preview.1.26201.1</XamarinAppleToolsMaciOSVersion>
<XamarinAppleToolsMaciOSVersion>1.0.0-preview.1.26228.1</XamarinAppleToolsMaciOSVersion>
</PropertyGroup>
<PropertyGroup Label="Platform Extensions">
<PlatformMauiMacOSVersion>0.3.0</PlatformMauiMacOSVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class FakeAppleProvider : IAppleProvider
public List<SimulatorInfo> Simulators { get; set; } = new();
public List<HealthCheck> HealthChecks { get; set; } = new();
public List<Device> Devices { get; set; } = new();
public AppleInstallResult InstallResult { get; set; } = new() { Status = "ok" };

public bool SelectXcodeResult { get; set; } = true;
public bool BootSimulatorResult { get; set; } = true;
Expand All @@ -36,6 +37,7 @@ public class FakeAppleProvider : IAppleProvider
public List<string> ShutdownSimulators { get; } = new();
public List<string> DeletedSimulators { get; } = new();
public List<(string Name, string DeviceType, string? Runtime)> CreatedSimulators { get; } = new();
public List<(IEnumerable<string>? Platforms, bool DryRun)> InstallCalls { get; } = new();

// --- IAppleProvider implementation ---

Expand Down Expand Up @@ -92,5 +94,11 @@ public bool DeleteSimulator(string udidOrName)

public List<HealthCheck> CheckHealth() => HealthChecks;

public Task<AppleInstallResult> InstallEnvironmentAsync(IEnumerable<string>? platforms = null, bool dryRun = false, CancellationToken cancellationToken = default)
{
InstallCalls.Add((platforms, dryRun));
return Task.FromResult(InstallResult);
}

public List<Device> GetDevices() => Devices;
}
78 changes: 78 additions & 0 deletions src/Cli/Microsoft.Maui.Cli/Commands/AppleCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.CommandLine;
using System.CommandLine.Parsing;
using Microsoft.Maui.Cli.Errors;
using Microsoft.Maui.Cli.Output;
using Microsoft.Maui.Cli.Providers.Apple;
using Microsoft.Maui.Cli.Utils;
Expand All @@ -22,6 +23,7 @@ public static Command Create()
command.Add(CreateXcodeCommand());
command.Add(CreateRuntimeCommand());
command.Add(CreateSimulatorCommand());
command.Add(CreateInstallCommand());

return command;
}
Expand Down Expand Up @@ -129,6 +131,82 @@ static Command CreateRuntimeCommand()
return runtimeCommand;
}

static Command CreateInstallCommand()
{
var platformOption = new Option<string[]>("--platform")
{
Description = "Platform(s) to ensure runtimes for (iOS, tvOS, watchOS, visionOS). If omitted, installs all available.",
Comment thread
rmarinho marked this conversation as resolved.
Outdated
AllowMultipleArgumentsPerToken = true
};

var installCommand = new Command("install", "Set up Apple development environment (CLT, runtimes)")
{
platformOption
};

installCommand.SetAction(async (ParseResult parseResult, CancellationToken ct) =>
{
var formatter = Program.GetFormatter(parseResult);

if (!PlatformDetector.IsMacOS)
{
formatter.WriteWarning("Apple install is only available on macOS.");
return 0;
Comment thread
rmarinho marked this conversation as resolved.
Outdated
}

var appleProvider = Program.AppleProvider;
var useJson = parseResult.GetValue(GlobalOptions.JsonOption);
var platforms = parseResult.GetValue(platformOption);
var dryRun = parseResult.GetValue(GlobalOptions.DryRunOption);

if (dryRun && !useJson)
formatter.WriteInfo("Dry run mode — no changes will be made.");

try
{
var result = await appleProvider.InstallEnvironmentAsync(
platforms is { Length: > 0 } ? platforms : null,
dryRun,
ct);

if (useJson)
{
formatter.Write(result);
}
else
{
if (result.XcodeVersion is not null)
formatter.WriteSuccess($"Xcode: {result.XcodeVersion}");
else
formatter.WriteWarning("Xcode: not found");

formatter.WriteInfo($"Command Line Tools: {(result.CommandLineToolsInstalled ? "installed" : "not installed")}");

if (result.Platforms.Count > 0)
formatter.WriteInfo($"Platforms: {string.Join(", ", result.Platforms)}");

if (result.Runtimes.Count > 0)
formatter.WriteInfo($"Runtimes: {string.Join(", ", result.Runtimes)}");

formatter.WriteInfo($"Status: {result.Status}");
}

return result.Status is "ok" or "skipped" ? 0 : 1;
}
catch (Exception ex) when (ex is not OperationCanceledException)
{
formatter.WriteError(new MauiToolException(ErrorCodes.AppleSetupFailed, "Apple install failed.", ex));
return 1;
}
catch (Exception ex)
{
return Program.HandleCommandException(formatter, ex);
}
});

return installCommand;
}
Comment thread
rmarinho marked this conversation as resolved.

static Command CreateSimulatorCommand()
{
var simCommand = new Command("simulator", "Manage iOS simulators");
Expand Down
2 changes: 2 additions & 0 deletions src/Cli/Microsoft.Maui.Cli/Errors/ErrorCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public static class ErrorCodes
public const string AppleCltNotFound = "E2202";
public const string AppleSimctlFailed = "E2203";
public const string AppleSimulatorNotFound = "E2204";
public const string AppleXcodeLicenseNotAccepted = "E2205";
public const string AppleSetupFailed = "E2206";
Comment thread
rmarinho marked this conversation as resolved.
Comment thread
rmarinho marked this conversation as resolved.

// Platform/SDK errors - Windows (E23xx)
public const string WindowsSdkNotFound = "E2301";
Expand Down
1 change: 1 addition & 0 deletions src/Cli/Microsoft.Maui.Cli/Output/MauiCliJsonContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace Microsoft.Maui.Cli.Output;
[JsonSerializable(typeof(List<RuntimeInfo>))]
[JsonSerializable(typeof(SimulatorInfo))]
[JsonSerializable(typeof(List<SimulatorInfo>))]
[JsonSerializable(typeof(AppleInstallResult))]
[JsonSerializable(typeof(StatusMessageResult))]
[JsonSerializable(typeof(VersionResult))]
[JsonSerializable(typeof(CliCommandResult))]
Expand Down
Loading