microsoft / cppwinrt

C++/WinRT
MIT License
1.65k stars 238 forks source link

IDL, H & CPP file association broken + item template confusing #972

Closed Gavin-Williams closed 3 years ago

Gavin-Williams commented 3 years ago

H and CPP files are not automatically associated with their corresponding IDL files - this has been the case any time I have tried C++/WinRT, which would be back in 2020, and now in 2021.

UWP Community Discord was very helpful in explaining that the way I get correct file association is by utilizing the C++ item template:

ViewModel (C++/WinRT) An empty interface definition suitable for XAML data binding, for a C++/WinRT UWP app.

Note that I would never in a million years think that this is the right item to use. I'm not using Xaml, I'm not doing data-binding, I'm not using a UI framework or a ViewModel pattern. How am I meant to read that and think 'that's what I use to make a WinRT Component class?

And back to the main issue, neither allowing the source generator to create the H & CPP files, nor manually adding source files give the correct file association. That ViewModel template did.

That means the documentation on creating runtime components is incorrect. And the obvious way to make a runtime component classes (manually creating IDL, H & CPP files) doesn't correctly configure the file association in the project file. And there is no obvious way to just add a runtime component class to the project.

I don't care for the technique of using build to generate the source files - you can throw that whole idea away as far as I'm concerned. To expand on that last comment, this whole procedure is hot garbage I reckon:

You can do a lot better than that.

Firstly, when IDL, H or CPP files are added to a project, the solution explorer needs to pick up immediately on association by name. So for example, when Model.h is added to a project which already contains Model.idl, the project file is automatically updated (with <\DependentUpon> or whatever) to create the association in solution explorer which results in h and cpp files being nested under the idl.

And secondly, you also need an item template, correctly categorized may I add..

Thirdly, in the project popup: RMB / Add / Class, you could add a checkbox for IDL.

kennykerr commented 3 years ago

Thanks for the feedback - we're well aware of the painful experience the lack of good IDE integration results in. Unfortunately, we're not IDE developers and the Visual Studio team has yet to provide the support to make this happen. I'd suggest bringing this feedback up with the Visual Studio team here:

https://developercommunity.visualstudio.com/search?space=62

sylveon commented 3 years ago

The documentation isn't fully incorrect, <DependentUpon> is a purely visual addition, doing it like documentation tells you to still works.