问题
I'm migrating my WPF desktop app from .NET Framwork to Core 3.0. I was using System.Windows.Forms.FolderBrowserDialog() and am now stuck on how to add this reference to the Core project. There is no "System.Windows.Forms" NuGet package available, is there? Is there any alternative way to display the FolderBrowserDialog in the Core?
Update
I created the Core project using the default template and then copy pasted .cs and .xaml files into it. The .csproj file looks like this:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
回答1:
You need to add to csproj additional switch:
<UseWindowsForms>true</UseWindowsForms>
Add it below UseWpf. Then try rebuild. After this you should be able to use Forms namespace.
回答2:
Looks like it already exists: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.folderbrowserdialog?view=netcore-3.0
For other porting issues, you might want to use the Windows Compatibility Pack which is used to help port apps to .NET Core
There also might be some more information out there related to WPF and this issue, since it's been around for awhile. This might be helpful Select folder dialog WPF, and updated for .NET Core.
Good luck with your upgrade!
来源:https://stackoverflow.com/questions/58844785/how-to-reference-system-windows-forms-in-net-core-3-0-for-wpf-apps