Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Bug: Incremental build with C++/WinRT 3.0 modules loses CppWinRTPlatformWinMDReferences, causing Windows.Foundation.Point could not be found

未关闭
#1,587 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
cpp

调研方向

检查 Microsoft.Windows.CppWinRT.targets 中 CppWinRTMakeReferenceProjection 附近的内容以及 CppWinRTPlatformWinMDReferences 输入。对于使用 CppWinRTConsumeModule 的模块提供程序,分别重现干净构建和增量构建,然后比较生成的 cppwinrt_ref.rsp 内容。完成的标准是:增量构建包含 Windows SDK contract 的 WinMD 引用,并且不再因解析 Windows.Foundation.Point 失败。

由索引模型根据 Issue 内容生成。

描述

Version

3.0.260520.1

Summary

I am migrating a WinAppSDK C++/WinRT project to the new C++/WinRT 3.0 module build.

The solution uses a dedicated module provider project:

<ProjectReference Include="..\..\CppWinRTModules\CppWinRTModules.vcxproj">
  <Project>{...}</Project>
  <CppWinRTConsumeModule>true</CppWinRTConsumeModule>
</ProjectReference>

A clean/rebuild works, but an incremental build fails during the C++/WinRT reference projection step.

The failure occurs when cppwinrt processes Microsoft.Graphics.winmd from the WinAppSDK experimental packages:

cppwinrt : error Type 'Windows.Foundation.Point' could not be found
 method: RedPrimary
 type: Microsoft.Graphics.Display.IDisplayAdvancedColorInfo
 database: ...\packages\Microsoft.WindowsAppSDK.InteractiveExperiences.2.0.14-experimental\metadata\10.0.18362.0\Microsoft.Graphics.winmd

The project does not use RedPrimary directly. This appears to happen while processing the metadata database.

Environment

Visual Studio: 18 Professional
MSVC: 14.51.36231
C++/WinRT NuGet: Microsoft.Windows.CppWinRT 3.0.260520.1
Windows SDK: 10.0.26100.0
Configuration: x64 Release / x64 Debug
WindowsAppSDK packages include:
  Microsoft.WindowsAppSDK.2.1.4-experimental8
  Microsoft.WindowsAppSDK.Foundation.2.0.22-experimental
  Microsoft.WindowsAppSDK.WinUI.2.1.1-experimental
  Microsoft.WindowsAppSDK.InteractiveExperiences.2.0.14-experimental
  Microsoft.WindowsAppSDK.AI.2.1.13-experimental
  Microsoft.WindowsAppSDK.Search.2.1.13-experimental
  Microsoft.WindowsAppSDK.Widgets.2.0.6-experimental
Reproducible example

Expected behavior

During the failing incremental build, the C++/WinRT diagnostic output shows that the direct WinMD references are present, but the platform WinMD references are empty:

CppWinRTPlatformWinMDReferences:
CppWinRTDirectWinMDReferences:
  ...\Microsoft.Graphics.winmd
  ...\Microsoft.UI.winmd
  ...\Microsoft.UI.Xaml.winmd
  ...

Then the generated command runs:

cppwinrt @"x64\Release\CppWinRTModules.vcxproj.cppwinrt_ref.rsp"

The tool output shows many in: entries for WinAppSDK package WinMDs, but no corresponding Windows SDK ref: entries. Therefore Microsoft.Graphics.winmd cannot resolve Windows.Foundation.Point.

After adding a workaround target, the same build succeeds. The log then shows CppWinRTPlatformWinMDReferences and CppWinRTPlatformWinMDInputs populated with the Windows SDK contract WinMDs such as Windows.Foundation.FoundationContract.winmd, Windows.Foundation.UniversalApiContract.winmd, Windows.Networking.Connectivity.WwanContract.winmd, etc.

Actual behavior

Clean/rebuild succeeds.

Incremental build fails because CppWinRTPlatformWinMDReferences is empty when CppWinRTMakeReferenceProjection runs, causing cppwinrt_ref.rsp to omit Windows SDK references.

Additional comments

Workaround

Adding this target to the project repairs the incremental build:

<Target Name="ForceCppWinRTPlatformWinMDReferences"
        BeforeTargets="CppWinRTMakeReferenceProjection">

  <ItemGroup Condition="'@(CppWinRTPlatformWinMDReferences)' == ''">
    <CppWinRTPlatformWinMDReferences Include="$(WindowsSDK_MetadataPathVersioned)\**\*.winmd" />
  </ItemGroup>

  <Message Text="Forced CppWinRTPlatformWinMDReferences from $(WindowsSDK_MetadataPathVersioned)"
           Importance="High"
           Condition="'@(CppWinRTPlatformWinMDReferences)' != ''" />

</Target>

After this, the build succeeds because the Windows SDK WinMDs are passed into the C++/WinRT projection step.

Notes

I also tried:
<CppWinRTEnableReferenceProjection>false</CppWinRTEnableReferenceProjection>
but that is not viable because the module provider then no longer generates required modules such as:

import winrt.Microsoft.UI;
import winrt.Microsoft.UI.Dispatching;
import winrt.Microsoft.UI.Xaml;
import winrt.Microsoft.UI.Xaml.Controls;
import winrt.Microsoft.UI.Xaml.Media;

I also tried excluding Microsoft.Graphics.Display, but that caused the module provider to generate almost no WinRT namespace modules, so that is not a usable workaround either.

The issue seems to be specifically that the incremental CppWinRTMakeReferenceProjection path does not populate CppWinRTPlatformWinMDReferences, while clean/rebuild does.

Minimal question

Is this expected behavior for C++/WinRT 3.0 module provider projects using true?

If not, should Microsoft.Windows.CppWinRT.targets ensure that CppWinRTPlatformWinMDReferences is populated before CppWinRTMakeReferenceProjection during incremental builds?

主要语言
C++
星标
1.9k
派生
281
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/cppwinrt 的其他 Issue

查看 microsoft/cppwinrt 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。