From c8da70d6fa1b573ff716cdb30579bc69853f49dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pol=C3=A1=C5=A1ek?= Date: Wed, 14 Jan 2026 02:49:51 +0100 Subject: [PATCH] CmdPal: Replace assembly metadata attributes with preprocessor directives (#44707) ## Summary of the Pull Request This PR replaces custom metadata attributes used to pass build-time information with preprocessor directives. It appears that metadata can be stripped from the final build output, even though it survived AOT in earlier tests on the main and stable branches. New preprocesor directives in Microsoft.CmdPal.UI: - `BUILD_INFO_PUBLISH_AOT` - when `PublishAot` MSBuild parameter is `true` - `BUILD_INFO_PUBLISH_TRIMMED `- when `PublishTrimmed` MSBuild parameter is `true` - `BUILD_INFO_CIBUILD `- when `CIBuild` MSBuild parameter is `true` Using preprocessor directives avoids this uncertainty and provides a more reliable solution. ## PR Checklist - [x] Closes: #44641 - [ ] **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 --- .github/actions/spell-check/expect.txt | 1 + .../Microsoft.CmdPal.UI/Helpers/BuildInfo.cs | 49 +++++++++++++------ .../Microsoft.CmdPal.UI.csproj | 31 +++++------- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index e384c89d13..3ed0361ef0 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -209,6 +209,7 @@ changecursor CHILDACTIVATE CHILDWINDOW CHOOSEFONT +CIBUILD cidl CIELCh cim diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Helpers/BuildInfo.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Helpers/BuildInfo.cs index 7f129d8b06..a276d38f47 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Helpers/BuildInfo.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Helpers/BuildInfo.cs @@ -2,7 +2,6 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Reflection; using System.Runtime.CompilerServices; namespace Microsoft.CmdPal.UI.Helpers; @@ -18,19 +17,41 @@ internal static class BuildInfo // Runtime AOT detection public static bool IsNativeAot => !RuntimeFeature.IsDynamicCodeSupported; - // From assembly metadata (build-time values) - public static bool PublishTrimmed => GetBoolMetadata("PublishTrimmed", false); + // build-time values + public static bool PublishTrimmed + { + get + { +#if BUILD_INFO_PUBLISH_TRIMMED + return true; +#else + return false; +#endif + } + } - // From assembly metadata (build-time values) - public static bool PublishAot => GetBoolMetadata("PublishAot", false); + // build-time values + public static bool PublishAot + { + get + { +#if BUILD_INFO_PUBLISH_AOT + return true; +#else + return false; +#endif + } + } - public static bool IsCiBuild => GetBoolMetadata("CIBuild", false); - - private static string? GetMetadata(string key) => - Assembly.GetExecutingAssembly() - .GetCustomAttributes() - .FirstOrDefault(a => a.Key == key)?.Value; - - private static bool GetBoolMetadata(string key, bool defaultValue) => - bool.TryParse(GetMetadata(key), out var result) ? result : defaultValue; + public static bool IsCiBuild + { + get + { +#if BUILD_INFO_CIBUILD + return true; +#else + return false; +#endif + } + } } 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 79ce3ff5ee..65174cb0b9 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj @@ -53,7 +53,7 @@ - DISABLE_XAML_GENERATED_MAIN + $(DefineConstants);DISABLE_XAML_GENERATED_MAIN @@ -291,24 +291,15 @@ - - - - <_Parameter1>PublishTrimmed - <_Parameter2>$(PublishTrimmed) - - - <_Parameter1>PublishAot - <_Parameter2>$(PublishAot) - - - <_Parameter1>CIBuild - <_Parameter2>$(CIBuild) - - - <_Parameter1>CommandPaletteBranding - <_Parameter2>$(CommandPaletteBranding) - - + + + $(DefineConstants);BUILD_INFO_PUBLISH_AOT + + + $(DefineConstants);BUILD_INFO_PUBLISH_TRIMMED + + + $(DefineConstants);BUILD_INFO_CIBUILD +