cppwinrt: [regression] Apps using DesktopWindowXamlSource start breaking in 2.0.201026.4 nuget

Before 2.0.201026.4, a Win32 app could do

#include <winrt/Windows.UI.Xaml.Hosting.h>
// ...
winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource dwxs{}

Beginning in 2.0.201026.4, apps will now get a error C2039: 'DesktopWindowXamlSource': is not a member of 'winrt::Windows::UI::Xaml::Hosting'

For UWP apps, they can reference the Desktop Extension SDK which contains the Windows.UI.Xaml.Hosting contract. However, I’m not sure if Win32 apps are able to do that (which is the whole purpose of the hosting apis, i.e. to be used from win32 apps).

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (11 by maintainers)

Most upvoted comments

It pretty much just works™️ for me. Any specific issue you’re hitting? We can take this offline (on Discord) if you want to, to avoid cluttering people’s inboxes.

Install the cppwinrt nuget in every project that needs to use cppwinrt

This is not a C++/WinRT bug. What’s happening in the repro is that the include path is set to multiple Generated Files folder from multiple different projects, meaning that the same headers exist multiple times on the include path. This is unsupported.

  • SampleCppApp: This is a Win32 app and so we automatically include all the WinMDs from the platform, including extension SDKs.
  • MyApp: This is a UWP where by default no WinMDs from extension SDKs are included.

Because the include paths are mixed, the compiler picks the header from MyApp that doesn’t include the Desktop extension and therefore it can’t find the types. The fix for this is to sort out the include paths. A project should never include the Generated Files folder from a different project in its own include path.

I am unable to repro with the above steps. Following up offline.

@jlaanstra simplified repro:

  • Git clone https://github.com/asklar/Xaml-Islands-Samples.git
  • Git checkout repro
  • Update NativeXamlIslands.sln to latest cppwinrt 2.0.210312.4 - this step is required
  • Restore
  • Copy Ryan’s cppwinrt.exe that gets you past the first bug o Copy \redmond\osg\teams\CORE\DEP\WinDev\asklar\bin\cppwinrt.exe E:\Xaml-Islands-Samples\packages\Microsoft.Windows.CppWinRT.191111.2\bin\
  • Rebuild and get this error: 4>E:\Xaml-Islands-Samples\Samples\Win32\SampleCppApp\XamlBridge.h(18,40): error C2039: 'DesktopWindowXamlSource': is not a member of 'winrt::Windows::UI::Xaml::Hosting' 4>E:\Xaml-Islands-Samples\obj\Win32\Debug\MyApp\Generated Files\winrt\Windows.UI.Xaml.Hosting.h(166): message : see declaration of 'winrt::Windows::UI::Xaml::Hosting'