NovemberMan
NovemberMan

Reputation: 75

What is the difference between TargetFramework net8.0-windows and net8.0?

With .NET we can create projects(.csproj files) that can have TargetFrameWork as net8.0-windows and net8.0

net8.0-windows

 <PropertyGroup>
 <TargetFramework>net8.0-windows</TargetFramework>
 <OutputType>Library</OutputType>
 <AppDesignerFolder>Properties</AppDesignerFolder>
 <UseWindowsForms>true</UseWindowsForms>
 <Nullable>enable</Nullable>
 <Platforms>x64</Platforms>
 </PropertyGroup>

net8.0

 <PropertyGroup>
 <TargetFramework>net8.0</TargetFramework>
 <OutputType>Library</OutputType>
 <AppDesignerFolder>Properties</AppDesignerFolder>
 <Platforms>x64</Platforms>
 </PropertyGroup>

What differences does they make to the executables? Does TargetFramework net8.0 will help to create libraries that are platform independent

Upvotes: 1

Views: 100

Answers (1)

DWilches
DWilches

Reputation: 23035

Using net8.0-windows makes certain Windows-only APIs available for your program (without having to add "ifs" testing for which Operating System you're using each time.

If you don't plan on using your application in Linux or Mac, net8.0-windows can save you several warnings that mention you'e using Windows only APIs.

From this page:

The net5.0, net6.0, net7.0, net8.0, and net.0 TFMs include technologies that work across different platforms. Specifying an OS-specific TFM makes APIs that are specific to an operating system available to your app, for example, Windows Forms or iOS bindings. OS-specific TFMs also inherit every API available to their base TFM, for example, the net9.0 TFM.

.NET 5 introduced the net5.0-windows OS-specific TFM, which includes Windows-specific bindings for WinForms, WPF, and UWP APIs. .NET 6 and later versions have additional OS-specific TFMs, for example, net6.0-ios.

Upvotes: 1

Related Questions