WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

UndockedRegFreeWinRT-AutoInitializer.cpp compile error in self-contained CX projects

Open Scottj1s opened this issue 3 years ago • 1 comments

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

  1. Create a WinAppSDK project with /ZW enabled for C++ sources (ClCompile.CompileAsWinRT = true, or "Consume Windows Runtime Extension" in the IDE)

  2. Add project properties:

    <WindowsPackageType>MSIX</WindowsPackageType>
    <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>

  1. 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

Scottj1s avatar Aug 11 '22 18:08 Scottj1s

@DrusTheAxe I managed to get a hacked up version of WindowsAppSDK-Nuget-Native.UndockedRegFreeWinRT.targets to support CX compilation. Three changes were needed:

  1. <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

  2. <LanguageStandard>stdcpp17</LanguageStandard> to address 1>...\UndockedRegFreeWinRT-AutoInitializer.cpp(14,1): error C2429: language feature 'nested-namespace-definition' requires compiler flag '/std:c++17

  3. <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.

Scottj1s avatar Aug 11 '22 21:08 Scottj1s

<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

DrusTheAxe avatar Aug 12 '22 17:08 DrusTheAxe

Closed per discussion, with recommended workaround: https://github.com/microsoft/WindowsAppSDK/discussions/2884

Scottj1s avatar Aug 22 '22 17:08 Scottj1s