如果我正在开发 WPF 项目,如何添加对 WinForms 的引用?

How to add reference to WinForms if I am developing a WPF project?

我在 .NET 5 上的 WPF 项目中使用第三方 nuget 包。当我尝试调用一些代码时,我收到这样的消息:

Severity    Code    Description Project File    Line    Suppression State
Error   CS0012  The type 'UserControl' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.    

第三方 WPF 库引用了名为 UserControl 的 Winforms Class。

当我点击黄红色图标自动解决问题时,Reference Manager window 打开...我检查了 Whosebug 并没有发现类似的情况。那么,接下来我该怎么办? 如何将对 Winforms 库的引用添加到 .NET 5 上的 WPF 项目?

我找到了:

Add reference of System.Windows.forms in .Net Core

所以,我必须将这一行添加到我的项目文件中:

    <UseWindowsForms>true</UseWindowsForms>