microsoft / microsoft/microsoft-ui-xaml
Build Tools Issue with Templated Controls
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
When creating a custom control using the ResourceDictionary approach, the build tools will generate the expected files, but the *.xaml.g.h file is empty.
As pasted below, the *.g.h file contains
```
#if defined(WINRT_FORCE_INCLUDE_SAMPLERESOURCEDICTIONARY_XAML_G_H) || __has_include("SampleResourceDictionary.xaml.g.h")
#include "SampleResourceDictionary.xaml.g.h"
#else
namespace winrt::Win2DSandbox::implementation
{
template
using SampleResourceDictionaryT = SampleResourceDictionary_base;
}
#endif
```
If `SampleResourceDictionary.xaml.g.h` cannot be found in the include paths, then the basic declaration is used, which for ResourceDictionary-based controls is often enough. However, if `SampleResourceDictionary.xaml.g.h` ends up in the include paths, because it is empty, it doesn't contain the declaration which results in loads of compile errors.
I would expect the `SampleResourceDictionary.xaml.g.h` would at least contain the basic declaration but also any additional content as needed.
The attached solution demonstrates the issue. As configured, the `$(GeneratedFilesDir)ResourceDictionary` directory is in the include paths which triggers all the compile errors. The solution should be configured to reference the needed packages but they are not included in the ZIP.
[Win2DSandbox.zip](https://github.com/user-attachments/files/19972591/Win2DSandbox.zip)
### Steps to reproduce the bug
Open the attached solution and ensure packages are installed.
Build.
### Expected behavior
_No response_
### Screenshots
_No response_
### NuGet package version
None
### Windows version
_No response_
### Additional context
_No response_
Contributor guide
Research direction
Start with the attached Win2DSandbox solution and inspect the generated SampleResourceDictionary.xaml.g.h and corresponding *.g.h files after building with $(GeneratedFilesDir)ResourceDictionary in the include paths. Trace the ResourceDictionary control generation path and verify that the generated header contains the basic declaration rather than being empty, then rebuild to confirm the compile errors are resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system, desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100