-
Notifications
You must be signed in to change notification settings - Fork 391
Description
Describe the bug
Consuming/using the Windows App SDK from C++ using Visual Studio is well documented. Visual Studio does all the heavy lifting (restoring nuget packages, invoking cppwinrt, etc.), so the whole process is quite hassle-free, it works out of the box. However, not everyone is using Visual Studio or MSBuild as build tools, especially in the C++ world.
Consuming “regular” 3rd party libraries from C++ is not a big deal (usually): there are header files, static libraries and/or import libraries and DLL files. Add the header files’ location to your include directory, link the given libraries, and you are good to go.
Consuming the Windows App SDK seems to be a whole lot more complex. In addition to the the usual files, there are also .winmd files, and a tool - cppwinrt.exe - to generate header files from winmd files for the WinRT C++ language projection. Some header files come pre-generated (like Microsoft.Xaml.UI.Window.h
), while others don’t (like Microsoft.UI.Xaml.Controls.h
). Visual Studio seems to generate these header files on the fly, as needed (Processing WinMD
lines in the build output). There’s also some extra machinery in the background, like bootstrapping. If you try and use certain functions without bootstrapping, you will get runtime errors. Good luck debugging and root causing those to combase.dll not being runtime patched in your application.
Just to give you some context: I was happy to see that using Win32 controls and WinUI 3 in the same (unpackaged) C++ application is finally supported. The Simple Island App sample shows the necessary steps to achieve interoperability between the two worlds. I thought I’d give this a try in my day job: a large, multi-platform, enterprise application with a Win32 UI on Windows. Said project - of course - does not use Visual Studio as a build tool, so my first step was to try and consume the Windows App SDK in this environment.
The end result? Countless hours of trying to “reverse engineer” what, how, and when Visual Studio does to make it all work. Initially, this method seemed to work, fixing error after error, however, I gave up after a few days. Many times errors manifested in deeper layers of the implementation, diagnosing them would have required either in-depth knowledge of the implementation details, or access to the source code - I have neither.
All in all, the introduction of Win32-WinUI 3 interop is a good sign: maybe Microsoft does want legacy applications to be modernized with the Windows App SDK and WinUI 3, which sounds great! However, probably not many of these kinds of applications use Visual Studio as a build tool, so improvements in this space (such as explicit support and documentation for this use case) would be very welcome.
Steps to reproduce the bug
Try to consume the Windows App SDK without Visual Studio and MSBuild, from a C++ project.
Expected behavior
The described scenario is supported, the necessary build steps are documented.
Screenshots
No response
NuGet package version
Windows App SDK 1.4.1: 1.4.230913002
Packaging type
Unpackaged
Windows version
Windows 11 version 22H2 (22621, 2022 Update)
IDE
Visual Studio 2022, Other
Additional context
No response