From 7463e2e976a0c2c6ae2617f9f1c1a66198168250 Mon Sep 17 00:00:00 2001 From: redth Date: Tue, 16 Jun 2026 16:16:40 -0400 Subject: [PATCH 01/13] Expose MaciOS artifact outputs Add public MSBuild item groups for final MaciOS build and publish artifacts so custom targets and CI can consume app bundles, IPA files, PKG installers, and Xcode archives with metadata. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docs/building-apps/build-items.md | 50 ++++++++++++ docs/building-apps/build-properties.md | 10 +++ docs/building-apps/build-targets.md | 23 ++++++ .../Xamarin.Shared.Sdk.Publish.targets | 6 ++ msbuild/Xamarin.Shared/Xamarin.Shared.targets | 81 +++++++++++++++++++ .../Xamarin.Shared/Xamarin.iOS.Common.targets | 26 ++++++ tests/dotnet/UnitTests/PostBuildTest.cs | 47 ++++++++++- 7 files changed, 239 insertions(+), 4 deletions(-) diff --git a/docs/building-apps/build-items.md b/docs/building-apps/build-items.md index 2fd81202cf18..9fb4cf1f8d4d 100644 --- a/docs/building-apps/build-items.md +++ b/docs/building-apps/build-items.md @@ -249,6 +249,56 @@ An item group that contains environment variables that will be set when the app > [!NOTE] > This only applies when launching the app from the command line (`dotnet run` or `dotnet build -t:Run`), not when launching from the IDE. +## MaciOSArtifactOutput + +An item group that contains final app artifacts produced by the build. This can include: + +* `.app` app bundles for iOS, tvOS, macOS, and Mac Catalyst apps. +* `.ipa` packages when [BuildIpa](build-properties.md#buildipa) is enabled. +* `.pkg` installer packages when [CreatePackage](build-properties.md#createpackage) is enabled. +* `.xcarchive` directories when [ArchiveOnBuild](build-properties.md#archiveonbuild) is enabled. + +The following metadata is set: + +* `ArtifactKind`: The artifact kind. Possible values are `AppBundle`, `Package`, and `Archive`. +* `PackageFormat`: The artifact format. Possible values are `app`, `ipa`, `pkg`, and `xcarchive`. +* `IsDirectory`: `true` for `.app` and `.xcarchive` outputs; `false` for `.ipa` and `.pkg` outputs. +* `PlatformName`: The Apple platform name, such as `iOS`, `tvOS`, `macOS`, or `MacCatalyst`. +* `TargetPlatformIdentifier`: The target platform identifier, such as `ios`, `tvos`, `macos`, or `maccatalyst`. +* `TargetFramework`: The target framework. +* `RuntimeIdentifier`: The runtime identifier when building with `RuntimeIdentifier`. +* `RuntimeIdentifiers`: The runtime identifiers when building with `RuntimeIdentifiers`. +* `Configuration`: The build configuration. +* `RelativePath`: The artifact file or directory name. +* `AppBundlePath`: The app bundle path associated with the artifact. +* `BundleIdentifier`: The resolved app bundle identifier. +* `CodeSigned`: Whether the app bundle was code signed. +* `PackageSigned`: Whether a `.pkg` installer package was signed. This metadata is only set for `.pkg` outputs. +* `BuildIpa`: The effective [BuildIpa](build-properties.md#buildipa) value. +* `CreatePackage`: The effective [CreatePackage](build-properties.md#createpackage) value. +* `ArchiveOnBuild`: The effective [ArchiveOnBuild](build-properties.md#archiveonbuild) value. + +Example: + +```xml + + + +``` + +See also the [GetMaciOSArtifactOutputs](build-targets.md#getmaciosartifactoutputs) target. + +## MaciOSPublishedArtifactOutput + +An item group that contains the `@(MaciOSArtifactOutput)` items produced by the `Publish` target. + +This item group has the same metadata as [MaciOSArtifactOutput](#maciosartifactoutput), plus: + +* `OriginalPath`: The corresponding path from `@(MaciOSArtifactOutput)`. + ## NativeReference An item group that contains any native references that should be linked into diff --git a/docs/building-apps/build-properties.md b/docs/building-apps/build-properties.md index 634396282b90..d656f44e6ee5 100644 --- a/docs/building-apps/build-properties.md +++ b/docs/building-apps/build-properties.md @@ -109,6 +109,8 @@ Only applicable to iOS projects (since only iOS projects can be built remotely f If an Xcode archive should be created at the end of the build. +Created archives are exposed in the [MaciOSArtifactOutput](build-items.md#maciosartifactoutput) item group. + ## BGenEmitDebugInformation Whether the `bgen` tool (the binding generator) should emit debug information or not. @@ -139,6 +141,8 @@ Only applicable to iOS and tvOS projects. See [CreatePackage](#createpackage) for macOS and Mac Catalyst projects. +Created IPA packages are exposed in the [MaciOSArtifactOutput](build-items.md#maciosartifactoutput) item group. + ## BundleCreateDump CoreCLR has a command-line utility called [`createdump`][createdump] to create @@ -350,6 +354,8 @@ Only applicable to macOS and Mac Catalyst projects. See [BuildIpa](#buildipa) for iOS and tvOS projects. +Created PKG packages are exposed in the [MaciOSArtifactOutput](build-items.md#maciosartifactoutput) item group. + ## Device Specifies which mobile device or simulator to target when using `dotnet run --device ` or MSBuild targets that interact with devices (such as `Run`, `Install`, or `Uninstall`). @@ -669,6 +675,8 @@ Specifies the path to the resulting .ipa file when creating an IPA package (see Only applicable to iOS and tvOS projects. +The resulting IPA is exposed in the [MaciOSArtifactOutput](build-items.md#maciosartifactoutput) item group. + ## IsAppExtension If a project is an app extension. @@ -1139,6 +1147,8 @@ Specifies the path to the resulting .pkg file when creating a package (see [Crea Only applicable to macOS and Mac Catalyst apps. +The resulting PKG is exposed in the [MaciOSArtifactOutput](build-items.md#maciosartifactoutput) item group. + ## PlutilPath The full path to the `plutil` command-line tool. diff --git a/docs/building-apps/build-targets.md b/docs/building-apps/build-targets.md index fbf0abff811e..3c0d449b5a7d 100644 --- a/docs/building-apps/build-targets.md +++ b/docs/building-apps/build-targets.md @@ -44,6 +44,29 @@ $ dotnet run --device UDID Added in .NET 11. +## GetMaciOSArtifactOutputs + +Builds the project and returns the `@(MaciOSArtifactOutput)` item group. This +target can be used by custom build scripts to query final `.app`, `.ipa`, +`.pkg`, and `.xcarchive` artifacts without invoking the `Publish` target. + +```shell +$ dotnet build -t:GetMaciOSArtifactOutputs +``` + +See [MaciOSArtifactOutput](build-items.md#maciosartifactoutput) for supported metadata. + +## GetMaciOSPublishedArtifactOutputs + +Publishes the project and returns the `@(MaciOSPublishedArtifactOutput)` item +group. + +```shell +$ dotnet publish -t:GetMaciOSPublishedArtifactOutputs +``` + +See [MaciOSPublishedArtifactOutput](build-items.md#maciospublishedartifactoutput) for supported metadata. + ## Run Builds the source code within a project and all dependencies, and then deploys and runs it diff --git a/dotnet/targets/Xamarin.Shared.Sdk.Publish.targets b/dotnet/targets/Xamarin.Shared.Sdk.Publish.targets index c053793baf15..3d585f8546f3 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.Publish.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.Publish.targets @@ -21,7 +21,13 @@ /> + + + %(MaciOSArtifactOutput.Identity) + + + diff --git a/msbuild/Xamarin.Shared/Xamarin.Shared.targets b/msbuild/Xamarin.Shared/Xamarin.Shared.targets index 8307a85ebf48..089afaad3a2e 100644 --- a/msbuild/Xamarin.Shared/Xamarin.Shared.targets +++ b/msbuild/Xamarin.Shared/Xamarin.Shared.targets @@ -2369,6 +2369,32 @@ Copyright (C) 2018 Microsoft. All rights reserved. + + + + AppBundle + app + true + $(_PlatformName) + $(TargetPlatformIdentifier) + $(TargetFramework) + $(RuntimeIdentifier) + $(RuntimeIdentifiers) + $(Configuration) + %(Filename)%(Extension) + $(AppBundleDir) + $(_BundleIdentifier) + true + false + $(BuildIpa) + $(CreatePackage) + $(ArchiveOnBuild) + + + +