8

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

0

1 Answer 1

11

Not funny....

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

duh..

Sign up to request clarification or add additional context in comments.

7 Comments

Those things are set by the WinForms template or the .NET Upgrade assistant. How did you create your project? In any case .NET 8 is .NET Core 8. You don't add references directly to system libraries. There's no GAC any more. The libraries are either included through the target SDK or as NuGet packages
Do you mean stuff like this has no meaning anymore in .NET8 (due to the fact that the gac no longer is used for .NET 8?) <ItemGroup> <Reference Include="WindowsBase" /></ItemGroup>
can you look at this page, there is a solution to a same problem stackoverflow.com/questions/70005465/…
If you want to include PresentationFramework assemblies, add <UseWPF>True</UseWPF> right after <UseWindowsForms>true</UseWindowsForms>. Other assemblies, as mentioned, are added as PackageReference (NuGet packages)
If I want to use <UseWPF> with .net web app and .net 8, what nuget packages I should add?
...why on earth would you want to use <UseWPF> within an ASP.NET project? That makes no sense...
and yet I'm asking this question.. in my legacy codebase anything is possible..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.