Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it OK to enable both Winforms and WPF for a .NET 6.0 application?

As shown here and here (both on the same Microsoft page) a .NET 6.0 application can target Winforms and WPF. But will that cause conflicts at some point? What isn't clear is whether both can be targeted in the same project.

So, is it OK to target both together or will alters the MSBuild pipeline to correctly process a Windows Forms project conflict with alters the MSBuild pipeline to correctly process a WPF project?

Here's how it looks in Visual Studio in the project's properties tab:

enter image description here

The reason I'm asking is because I want to use certain classes from Winforms in a WPF application.

like image 701
ispiro Avatar asked Oct 15 '25 06:10

ispiro


1 Answers

Yes, it's OK and there are valid scenarios which you may want to add both frameworks. It's already mentioned in the documentations, you can add both, if necessary:

  • Add a UI framework property (or both, if necessary):
    • Set UseWPF to true to import and use WPF.
    • Set UseWindowsForms to true to import and use WinForms.

And also the example shows the same:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>

    <UseWPF>true</UseWPF>
    <!-- and/or -->
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

</Project>
like image 55
Reza Aghaei Avatar answered Oct 17 '25 20:10

Reza Aghaei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!