Skip to content

dotnet 10 已知问题 构建 WPF 时提示 System.Private.Windows.GdiPlus 程序集未找到错误

Updated: at 01:08,Created: at 23:29

本文记录 dotnet 10 的已知问题,将会导致 WPF 项目构建的时候给出错误

此问题开始是在 https://github.com/dotnet/wpf/issues/11246 被报告的

此问题已修复,详细请看 https://github.com/dotnet/dotnet/pull/3120

本文写于 2025年11月15日 此时为 .NET 10 首个正式版本发布,此问题为首个正式版本带来的。此问题在首个正式版本发布之后才修复,需要等待下个版本 SDK 发布才能解决此问题

详细错误信息如下

error CS0012: The type 'IImage' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.Windows.GdiPlus, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

如果等不及 SDK 更新,可使用以下补丁方法:

用户修复构建:

<!-- Workaround for https://github.com/dotnet/wpf/issues/11246 -->
<!-- Copy from https://github.com/dotnet/sdk/issues/51173#issuecomment-3392609295 -->
<Target Name="_AddDrawingReference" AfterTargets="ResolveTargetingPackAssets">
<ItemGroup>
<Reference Condition="'%(Reference.FileName)' == 'PresentationCore'"
Include="%(Reference.RootDir)%(Reference.Directory)System.Drawing.Common.dll;
%(Reference.RootDir)%(Reference.Directory)System.Private.Windows.GdiPlus.dll" />
</ItemGroup>
</Target>

用于自包含 self contained 应用:

<!-- Copy from https://github.com/dotnet/windowsdesktop/issues/5405#issuecomment-3548429691 -->
<Target Name="_AddDrawingRuntime"
AfterTargets="ResolveRuntimePackAssets"
Condition="'$(SelfContained)' == 'true' AND '$(UseWPF)' == 'true' AND '$(UseWinforms)' != 'true'">
<ItemGroup>
<_additionalRuntimePackAsset Condition="'%(RuntimePackAsset.FileName)' == 'PresentationCore'"
Include="@(RuntimePackAsset->'%(RootDir)%(Directory)System.Drawing.Common.dll')" DestinationSubPath="System.Drawing.Common.dll" />
<_additionalRuntimePackAsset Condition="'%(RuntimePackAsset.FileName)' == 'PresentationCore'"
Include="@(RuntimePackAsset->'%(RootDir)%(Directory)System.Private.Windows.GdiPlus.dll')" DestinationSubPath="System.Private.Windows.GdiPlus.dll" />
<RuntimePackAsset Include="@(_additionalRuntimePackAsset)" />
<ReferenceCopyLocalPaths Include="@(_additionalRuntimePackAsset)" />
</ItemGroup>
</Target>

等待下个 .NET 10 正式版本发布之后,以上补丁代码需要删掉

参考链接:


知识共享许可协议

原文链接: http://blog.lindexi.com/post/dotnet-10-%E5%B7%B2%E7%9F%A5%E9%97%AE%E9%A2%98-%E6%9E%84%E5%BB%BA-WPF-%E6%97%B6%E6%8F%90%E7%A4%BA-System.Private.Windows.GdiPlus-%E7%A8%8B%E5%BA%8F%E9%9B%86%E6%9C%AA%E6%89%BE%E5%88%B0%E9%94%99%E8%AF%AF

本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。 欢迎转载、使用、重新发布,但务必保留文章署名 林德熙 (包含链接: https://blog.lindexi.com ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我 联系