Search code examples
c#wpfvisual-studiocmake

WPF Project Generated from CMake has wrong VS context menus


This project is a good example of what I'm trying to do, namely to generate a WPF C# project using CMake.

Everything works as expected, except the Project(Example)->Add context menu from Solution Explorer shows options for Windows Forms, and not for WPF.

Should have WPF options, not WinForms

Instead of these Window Forms options, I expect to see the following options (from a non-CMake project):

The above should look like this

What is missing from the CMake project to enable this?


Solution

  • After some careful comparison of the project files, the missing piece was ProjectTypeGuids in the generated .csproj file.

    A WPF project should be set up in CMake with the following:

    set_target_properties(${PROJECT_NAME} PROPERTIES
        # These GUIDs define the project types, which control things like what context menus are available in VS.
        # The first is WPF, the second is C#.
        VS_GLOBAL_PROJECT_TYPES "{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
    )