Advertisement
Intermediate .NET, .NET CLI, SDK & Project Structure (csproj)

How does target framework moniker (TFM) selection, like net8.0 or net8.0-windows, affect what a project can do?

Short answer

The TargetFramework property specifies which .NET version's APIs and behaviors the project compiles against; platform-specific TFMs like net8.0-windows unlock Windows-only APIs (e.g., WinForms, Registry access) at the cost of losing cross-platform compatibility.

Save .NET mock interview
Advertisement
AModel answer
The TargetFramework property specifies which .NET version's APIs and behaviors the project compiles against; platform-specific TFMs like net8.0-windows unlock Windows-only APIs (e.g., WinForms, Registry access) at the cost of losing cross-platform compatibility. Choosing the right TFM balances access to newer APIs and platform features against the breadth of environments the application can run on.
<PropertyGroup>
  <TargetFramework>net8.0</TargetFramework>
  <!-- vs -->
  <TargetFramework>net8.0-windows</TargetFramework>
</PropertyGroup>
Real-world example
A cross-platform background service targets plain net8.0 to run on Linux containers, while a companion WinForms configuration tool targets net8.0-windows to access Windows-specific UI APIs.
Likely follow-ups
  • How does multi-targeting (net8.0
  • net481) work in one csproj?
  • What happens if you reference a platform-specific API without the right TFM?
Related topics