UndockedRegFreeWinRT-AutoInitializer.cpp compile error in self-contained CX projects
Describe the bug
WinAppSDK 1.2 Experimental adds support for automatically initializing undocked reg-free WinRT support. This breaks CX compilation: UndockedRegFreeWinRT-AutoInitializer.cpp:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vccorlib.h(356,9): error C3940: 'EventRegistrationToken': identifier not found - possible mismatch between compiler and library versions. Please ensure vccorlib.h/.lib, vccorlib120.dll and c1xx.dll match [C:\src\Fresco.sjones\platform\windows\common\gemini-bridge-test\gemini-bridge-test.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vccorlib.h(356,9): error C1903: unable to recover from previous error(s); stopping compilation [C:\src\Fresco.sjones\platform\windows\common\gemini-bridge-test\gemini-bridge-test.vcxproj]
The fix may be as simple as disabling /ZW for this file when adding it to the project:
<ClCompile Include="UndockedRegFreeWinRT-AutoInitializer.cpp">
<CompileAsWinRT>false</CompileAsWinRT>
</ClCompile>
Steps to reproduce the bug
-
Create a WinAppSDK project with /ZW enabled for C++ sources (ClCompile.CompileAsWinRT = true, or "Consume Windows Runtime Extension" in the IDE)
-
Add project properties:
<WindowsPackageType>MSIX</WindowsPackageType>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
- Build
Expected behavior
Compilation fails on UndockedRegFreeWinRT-AutoInitializer.cpp.
Workaround:
Disable auto-initialization of undocked reg-free support:
<WindowsAppSdkUndockedRegFreeWinRTInitialize>false</WindowsAppSdkUndockedRegFreeWinRTInitialize>
Screenshots
No response
NuGet package version
1.2.220727.1-experimental1
Packaging type
Packaged (MSIX)
Windows version
Windows 11 version 21H2 (22000)
IDE
Visual Studio 2022
Additional context
No response
@DrusTheAxe I managed to get a hacked up version of WindowsAppSDK-Nuget-Native.UndockedRegFreeWinRT.targets to support CX compilation. Three changes were needed:
-
<CompileAsWinRT>false</CompileAsWinRT>to address C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vccorlib.h(356,9): error C3940: 'EventRegistrationToken': identifier not found - possible mismatch between compiler and library versions. Please ensure vccorlib.h/.lib, vccorlib120.dll and c1xx.dll match C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vccorlib.h(356,9): error C1903: unable to recover from previous error(s); stopping compilation -
<LanguageStandard>stdcpp17</LanguageStandard>to address 1>...\UndockedRegFreeWinRT-AutoInitializer.cpp(14,1): error C2429: language feature 'nested-namespace-definition' requires compiler flag '/std:c++17 -
<PreprocessorDefinitions>WINAPI_PARTITION_SYSTEM;%(PreprocessorDefinitions)</PreprocessorDefinitions>to work around changes in the Windows SDK. Prior to SDK 22000, LoadLibraryExW was excluded for apps (WACK restricted). So the auto-initializer may need to also be conditioned on both the WINAPI_FAMILY definition, and the version of the SDK.
<shudder> I have reservations about the potential long tail of issues. This is very much a question for @MikeHillberg - does WinAppSDK support CX and to what extent?
This bug's on hold pending that policy resolution
Closed per discussion, with recommended workaround: https://github.com/microsoft/WindowsAppSDK/discussions/2884