From 42bf3908cb9233c4c96808c1b1aa1c75042db002 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 27 Aug 2026 00:57:49 +0200 Subject: [PATCH 1/3] [msbuild] Embed app extensions even when ReferenceOutputAssembly is false. Fixes #26453 The `_ResolveAppExtensionReferences` target only added a referenced app extension to `_ResolvedAppExtensionReferences` when the project reference didn't have `ReferenceOutputAssembly=false`. The `MSBuild` task itself was executed unconditionally, so the app extension was still built - it just never made it into the container app's `PlugIns` directory. The build succeeded with no errors and no warnings, which made this very hard to diagnose. `ReferenceOutputAssembly=false` means "don't reference the output assembly of this project reference from the compiler", which is exactly what you'd want for an app extension (the container app never compiles against the extension's code - they're separate processes). It says nothing about whether the extension should be embedded in the container app, so it shouldn't affect the embedding at all. This condition dates back to when app extension support was first added (xamarin/maccore@71e3baeeb2d8d8421b0d67943e0925ea2916cc60), and there doesn't seem to be any reason for it, so just remove it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 57a20054-5162-48cd-97a2-58bceaa09807 --- msbuild/Xamarin.Shared/Xamarin.Shared.targets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/msbuild/Xamarin.Shared/Xamarin.Shared.targets b/msbuild/Xamarin.Shared/Xamarin.Shared.targets index 761ffa913492..fe52a63f9622 100644 --- a/msbuild/Xamarin.Shared/Xamarin.Shared.targets +++ b/msbuild/Xamarin.Shared/Xamarin.Shared.targets @@ -2861,7 +2861,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. Properties="%(_AppExtensionReferenceWithConfigurationExistent.SetConfiguration); %(_AppExtensionReferenceWithConfigurationExistent.SetPlatform)" Condition="'@(_AppExtensionReferenceWithConfigurationExistent)' != '' and '$(_BuildReferencedExtensionProjects)' != 'true'"> - + @@ -2871,7 +2871,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. Properties="%(_AppExtensionReferenceWithConfigurationExistent.SetConfiguration); %(_AppExtensionReferenceWithConfigurationExistent.SetPlatform)" Condition="'@(_AppExtensionReferenceWithConfigurationExistent)' != '' and '$(_BuildReferencedExtensionProjects)' == 'true' "> - + Date: Thu, 27 Aug 2026 01:20:28 +0200 Subject: [PATCH 2/3] [tests] Add a test for embedding app extensions with ReferenceOutputAssembly=false Verified that this test fails without the previous commit's fix, and passes with it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 57a20054-5162-48cd-97a2-58bceaa09807 --- tests/dotnet/ExtensionConsumer/shared.csproj | 1 + tests/dotnet/UnitTests/ProjectTest.cs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/tests/dotnet/ExtensionConsumer/shared.csproj b/tests/dotnet/ExtensionConsumer/shared.csproj index 62450d5df793..93b977b777f1 100644 --- a/tests/dotnet/ExtensionConsumer/shared.csproj +++ b/tests/dotnet/ExtensionConsumer/shared.csproj @@ -17,6 +17,7 @@ true + $(TestReferenceOutputAssembly) diff --git a/tests/dotnet/UnitTests/ProjectTest.cs b/tests/dotnet/UnitTests/ProjectTest.cs index 1da566da3985..8532ba9e34c8 100644 --- a/tests/dotnet/UnitTests/ProjectTest.cs +++ b/tests/dotnet/UnitTests/ProjectTest.cs @@ -1965,6 +1965,20 @@ public void BuildProjectsWithExtensionsOnRemoteWindows (ApplePlatform platform, BuildProjectsWithExtensionsImpl (platform, runtimeIdentifier, isNativeAot, AddRemoteProperties ()); } + // App extensions must be embedded in the container app even when the project reference + // says ReferenceOutputAssembly=false. Ref: https://github.com/dotnet/macios/issues/26453 + [TestCase (ApplePlatform.iOS, "iossimulator-x64")] + [TestCase (ApplePlatform.TVOS, "tvossimulator-x64")] + [TestCase (ApplePlatform.MacOSX, "osx-x64")] + [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64")] + public void BuildProjectsWithExtensionsWithoutReferenceOutputAssembly (ApplePlatform platform, string runtimeIdentifier) + { + var properties = new Dictionary { + { "TestReferenceOutputAssembly", "false" }, + }; + BuildProjectsWithExtensionsImpl (platform, runtimeIdentifier, isNativeAot: false, properties); + } + void BuildProjectsWithExtensionsImpl (ApplePlatform platform, string runtimeIdentifier, bool isNativeAot, Dictionary? properties = null) { Configuration.IgnoreIfIgnoredPlatform (platform); From 5d1628a83c57feb0d77b59b0eda84903099b6ab5 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 27 Aug 2026 16:53:11 +0200 Subject: [PATCH 3/3] [tests] Also test embedding prebuilt app extensions with ReferenceOutputAssembly=false The '_ResolveAppExtensionReferences' target has two invocations, and both had the bug. The existing test only covers the one that builds the referenced extension projects, since '_BuildReferencedExtensionProjects' defaults to true, so add a test for the other one as well (which is the code path some versions of the IDE take). Verified that this test fails if the fix is reverted. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 57a20054-5162-48cd-97a2-58bceaa09807 --- tests/dotnet/UnitTests/ProjectTest.cs | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/dotnet/UnitTests/ProjectTest.cs b/tests/dotnet/UnitTests/ProjectTest.cs index 8532ba9e34c8..94b70c1a9a34 100644 --- a/tests/dotnet/UnitTests/ProjectTest.cs +++ b/tests/dotnet/UnitTests/ProjectTest.cs @@ -1979,6 +1979,36 @@ public void BuildProjectsWithExtensionsWithoutReferenceOutputAssembly (ApplePlat BuildProjectsWithExtensionsImpl (platform, runtimeIdentifier, isNativeAot: false, properties); } + // Same as the previous test, but for the code path taken when the extension projects have + // already been built (which is what some versions of the IDE do). This exercises the other + // invocation in the _ResolveAppExtensionReferences target. + [TestCase (ApplePlatform.iOS, "iossimulator-x64")] + [TestCase (ApplePlatform.TVOS, "tvossimulator-x64")] + [TestCase (ApplePlatform.MacOSX, "osx-x64")] + [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64")] + public void BuildProjectsWithPrebuiltExtensionsWithoutReferenceOutputAssembly (ApplePlatform platform, string runtimeIdentifier) + { + Configuration.IgnoreIfIgnoredPlatform (platform); + + var consumingProjectDir = GetProjectPath ("ExtensionConsumer", runtimeIdentifier, platform, out var appPath); + var extensionProjectDir = GetProjectPath ("ExtensionProject", platform: platform); + + Clean (extensionProjectDir); + Clean (consumingProjectDir); + + // Build the extension project first, ... + DotNet.AssertBuild (extensionProjectDir, GetDefaultProperties (runtimeIdentifier)); + + // ... and then build the container app without building the extension project again. + var properties = GetDefaultProperties (runtimeIdentifier); + properties ["TestReferenceOutputAssembly"] = "false"; + properties ["_BuildReferencedExtensionProjects"] = "false"; + DotNet.AssertBuild (consumingProjectDir, properties); + + var extensionPath = Path.Combine (appPath, GetPlugInsRelativePath (platform), "ExtensionProject.appex"); + Assert.That (Directory.Exists (extensionPath), $"App extension directory does not exist: {extensionPath}"); + } + void BuildProjectsWithExtensionsImpl (ApplePlatform platform, string runtimeIdentifier, bool isNativeAot, Dictionary? properties = null) { Configuration.IgnoreIfIgnoredPlatform (platform);