Skip to content

VS: add VS_CSHARP_* sourcefile property and CSharpUtilities.cmake

This is a follow up on the recently finished work on C# support. Obviously not yet finished. I mark this as WIP because I need feedback/information

  • if the concept is good enough
  • what the names of
    • the proposed properties
    • cmake functions
    • cmake modules should be

Turns out the currently implemented mechanism of adding XML tags like <DependentUpon>, <AutoGen>, <SubType> etc. is not flexible enough for Visual Studio. Actually for me it is not clear what tagnames exist and where I could find them documented. Even worse I wouldn't want to have a source file property for each and every new tag that comes along. I stumbled upon this when I ported some legacy code base which uses Windows Forms to the CMake build process.

So here is my current proposal:

  • introduce a property prefix (similar to target property VS_GLOBAL_) where a tagname and a value can be defined arbitrarily. The current implementation uses the name VS_CSHARP_* because the source file property is bound to Visual Studio and C#. Better names welcome.
  • add a CMake module (I call it CSharpUtilities.cmake at the moment) which provides some functions to set the source properties as automated as possible
  • remove hard coded auto generation of XML tags in .csproj as much as possible to avoid confusion

The CSharpUtilities.cmake currently provide three functions:

  • csharp_set_windows_forms_properties
  • csharp_set_designer_cs_properties
  • csharp_set_xaml_cs_properties

Each of these just take a list of source files as parameters and sets the necessary source file properties automatically.


The C# support in general works very well without this MR. On the other hand this is needed for good support of Windows Forms and maybe other Visual Studio technologies that I am not aware of yet. Not sure if this could be a candidate for 3.8 or if it would introduce too much changes.

Merge request reports