C# WPF .NET Core和.NET5之后引用System.Windows.Forms的解决方案
- 双击项目名称打开工程文件(.csporj)
- 添加“Microsoft.WindowsDesktop.App.WindowsForms”引用;
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>WinExe</OutputType><TargetFramework>net8.0-windows</TargetFramework><Nullable>enable</Nullable><ImplicitUsings>enable</ImplicitUsings><UseWPF>true</UseWPF></PropertyGroup><ItemGroup><FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" /></ItemGroup>
</Project>
- 重新加载项目;