From 95e6ff5b8062bc54f636db0117ca4ddb46ac249b Mon Sep 17 00:00:00 2001 From: leileizhang Date: Fri, 20 Jun 2025 12:59:19 +0800 Subject: [PATCH] [CmdPal][AOT] Make Adaptive Card rendering AOT-compatible (#40134) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary of the Pull Request ### 1. Make AdaptiveCards WinUI3 AOT Compatible The AdaptiveCards.WinUI3 NuGet packages ship with precompiled WinRT projections (RendererCsProjection.dll, etc.), which are not trim/AOT-safe. These projections internally use APIs like ComWrappersSupport.GetObjectReferenceForInterface, which break under PublishAot. To resolve this: - We exclude their compile assets to avoid using the shipped C# projections. - Use the .winmd metadata files with CsWinRT to regenerate our own AOT-compatible projections. - Manually copy the required native .dlls from the NuGet package. ### 2. Ensure AOT-Compatible Transitive Dependency The AdaptiveCards.Templating package depends on Microsoft.Bot.AdaptiveExpressions.Core, but doesn’t pin an AOT-safe version. We explicitly version Microsoft.Bot.AdaptiveExpressions.Core to 4.23.0 to ensure compatibility with NativeAOT. ## PR Checklist - [x] **Closes:** [#40133](https://github.com/microsoft/PowerToys/issues/40133) - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed --- Directory.Packages.props | 3 +- NOTICE.md | 3 +- .../Microsoft.CmdPal.UI.ViewModels.csproj | 29 +++++++++++++++++-- .../Microsoft.CmdPal.UI.csproj | 15 ---------- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 8651672751..bb8dd4d74f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -5,7 +5,8 @@ - + + diff --git a/NOTICE.md b/NOTICE.md index 60b480d6c0..bb03f9ade1 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -1493,7 +1493,7 @@ SOFTWARE. - AdaptiveCards.ObjectModel.WinUI3 2.0.0-beta - AdaptiveCards.Rendering.WinUI3 2.1.0-beta -- AdaptiveCards.Templating 2.0.2 +- AdaptiveCards.Templating 2.0.5 - Appium.WebDriver 4.4.5 - Azure.AI.OpenAI 1.0.0-beta.17 - CommunityToolkit.Common 8.4.0 @@ -1518,6 +1518,7 @@ SOFTWARE. - Markdig.Signed 0.34.0 - MessagePack 3.1.3 - Microsoft.Bcl.AsyncInterfaces 9.0.6 +- Microsoft.Bot.AdaptiveExpressions.Core 4.23.0 - Microsoft.CodeAnalysis.NetAnalyzers 9.0.0 - Microsoft.Data.Sqlite 9.0.6 - Microsoft.Diagnostics.Tracing.TraceEvent 3.1.16 diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Microsoft.CmdPal.UI.ViewModels.csproj b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Microsoft.CmdPal.UI.ViewModels.csproj index 8057bb09be..37c89fde07 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Microsoft.CmdPal.UI.ViewModels.csproj +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Microsoft.CmdPal.UI.ViewModels.csproj @@ -14,11 +14,22 @@ SA1313; + + AdaptiveCards.ObjectModel.WinUI3;AdaptiveCards.Rendering.WinUI3 + true + + - + + + compile + + + compile + all @@ -28,7 +39,21 @@ - + + + + runtimes\win10-$(Platform)\native + + + + + + + + + + diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj b/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj index 3cd82da3ba..c3840c074e 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj @@ -89,10 +89,6 @@ - - - - @@ -177,17 +173,6 @@ true - - - - - runtimes\win10-$(Platform)\native - - - - - PreserveNewest