mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-05-18 05:05:25 +02:00
Diagnostic / prototype fix for the LNK2038 C++/WinRT version mismatch that has been failing PowerToys CI on every batched-CI run since commit `59eefd9581` (5/14): ` SettingsAPI.lib(settings_objects.obj): error LNK2038: mismatch detected for 'C++/WinRT version': value '2.0.250303.1' doesn't match value '2.0.250303.5' in main.obj [src/modules/GrabAndMove/GrabAndMove/GrabAndMove.vcxproj] ` ## Root cause GrabAndMove.vcxproj does not import the `Microsoft.Windows.CppWinRT` NuGet package, so `main.cpp` picks up `<winrt/Windows.Foundation.h>` (included transitively via `SettingsAPI/settings_objects.h` -> `common/utils/json.h`) from the **Windows SDK's in-box CppWinRT** instead of the repo-pinned NuGet version. After the SHINE-VS18-Latest agent image picked up a newer Windows SDK shipping `CppWinRT 2.0.250303.5`, `main.obj` began emitting that version via `#pragma detect_mismatch`, while `SettingsAPI.lib` continued to be built against the pinned NuGet `2.0.250303.1`. The linker rejects the mix. This was masked while the agent SDK happened to ship a matching CppWinRT version, and surfaced after #47470 (Bump WindowsAppSDK to 2.0.1) plus the agent image roll. ## Fix Mirror the canonical CppWinRT NuGet wiring used by every other native vcxproj in the repo (see `src/common/SettingsAPI/SettingsAPI.vcxproj` for the reference pattern): - Add `packages.config` pinning `Microsoft.Windows.CppWinRT 2.0.250303.1`. - Import the props after `Microsoft.Cpp.Default.props`. - Import the targets in an `ExtensionTargets` `ImportGroup`. - Add `EnsureNuGetPackageBuildImports` for restore-time validation. ## Validation - Local x64/Release build of GrabAndMove.vcxproj clean (linked against SettingsAPI.lib without LNK2038). - (Local SDK on the dev box already ships matching CppWinRT 2.0.250303.1, so the LNK2038 cannot reproduce locally; the CI pool agent has the newer SDK that exposes the latent issue.) - Awaiting PowerToys CI to confirm fix on the agent image. ## Related - #47470 (Bump WindowsAppSDK to 2.0.1) — preceded but did not directly cause this; just changed which CppWinRT was sitting in the include path. - Failing CI runs: 319304, 319351, 319593 (all on shine-oss PowerToys CI definition 3).