Skip to content

Missing Linux TargetFrameworkMoniker #27061

Open
@hansmbakker

Description

@hansmbakker

Is your feature request related to a problem? Please describe.

I am trying to create a cross-platform project with platform-specific implementations of several classes.

For most platforms, it would be possible to use the TargetFrameworkMoniker to conditionally include files like MAUI does (see e.g. https://github.com/dotnet/maui/blob/main/src/Essentials/src/Essentials.csproj). However, no TargetFrameworkMoniker is available for Linux.

This currently being unavailable also has the consequence that APIs like https://github.com/dotnet/runtime/pull/69980/files need an [UnsupportedPlatform("windows")] attribute rather than only making the APIs available on Unix OSes.

Describe the solution you'd like

  • A net7.0-linux TargetFrameworkMoniker

  • alternative considered: OperatingSystem.IsLinux() - this relies on runtime analysis and makes methods larger or requires a wrapper that returns a platform-specific implementation at runtime. This also has the limitation that the called / referenced code needs to be referenced even when being compiled for Windows and vice versa - which leads to impossible situations. Especially for technology like bluetooth or other device support code you need to reference platform-specific TFMs which I believe you can't do from a "neutral" net7.0 project.

  • alternative considered: using inverse #if to assume that

    if it is not Windows, iOS, Android, MacOS - it must be Linux

    Pseudocode: #if !(WINDOWS || MACOS || IOS || ANDROID). This seems brittle.

Additional context

These pages have no pointers about workarounds for this case:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions