Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference Windows Forms in .NET 8 project possible? [duplicate]

Googling for a while here in no direction at all...

We've got a big solution which we are migrating to .NET 8 (from .NET 4.8.1).

Got most of it sorted, but for some reason can't seem to figure out if it is possible to reference winforms assemblies from .NET 8.

Googling suggests Microsoft even adds new functionality for Winforms in .NET 8. So I guess it should be possible.

Trying to get it work:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0-windows</TargetFramework>
    <RootNamespace>IAI.Common.Utilities.Utils</RootNamespace>
    <AssemblyName>IAI.Common.Utilities.Utils</AssemblyName>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..\IAI.Common.Utilities.Logging\IAI.Common.Utilities.Logging.csproj" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="DotNetZip" Version="1.16.0" />
    <PackageReference Include="Extensions.Serialization" Version="3.3.0" />
    <PackageReference Include="log4net" Version="2.0.15" />
    <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3"/> <!-- Doesn't work -->
    <PackageReference Include="System.Management.Automation" Version="7.4.1" />
    <PackageReference Include="TestableIO.System.IO.Abstractions" Version="20.0.15" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="WindowsBase" /> <!-- Doesn't work -->
    <Reference Include="System.Windows.Forms" /> <!-- Doesn't work -->
  </ItemGroup>
  <ItemGroup>
    <Compile Update="Timer\TimerAdaper.cs" />
  </ItemGroup>
</Project>

None of the attempts allow me to include namespace

System.Windows.Forms

This suggest it should be possible, right?

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-8.0

like image 277
bas Avatar asked Jun 18 '26 21:06

bas


1 Answers

Not funny....

  <PropertyGroup>
    <TargetFramework>net8.0-windows</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms> <----- .....

duh..

like image 141
bas Avatar answered Jun 21 '26 11:06

bas



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!