Skip to content

Is it possible to set a condition to split windows and Linux platform logic? #252

Open
@datoml

Description

@datoml

Hello.
As far as I understand I am able to implement platform-specific logic based on the defined target frameworks.

The goal I am trying to achieve is to create a cross-platform library that is able to provide a USB communication layer for Windows, Linux and Android.

Implementing the Android part was easy because there is an existing TFM, in my case I used monodroid9.0, and I added a condition like the following in the csproj file.

<ItemGroup Condition=" '$(TargetFramework)' == 'monoandroid9.0' ">
	<Compile Include="Platforms\Android\*.cs" />
</ItemGroup>

But unfortunately, there is not a specific separation between Windows and Linux based on the available TFMs. Even .net5.0 has not specific TFMs for Linux.
I also found no informations why thats a case but I can imagine that its hard to find a common API for linux operation system?

I also looked up some projects from the dotnet runtime but I found no good solution so far.

After some further investigations it seems I can separat Windows and Linux logic with the RuntimeInformation.IsOSPlatform but this would result in a lot of IF ELSE statements.

Would it be possible to create some kind of "custom" TFM, so I am able to split the logic like I can do with Android?

A nice result would be to structure it like this in the csproj.

<ItemGroup Condition=" '$(TargetFramework)' == 'monoandroid9.0' ">
	<Compile Include="Platforms\Android\*.cs" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0-windows' ">
	<Compile Include="Platforms\Windows\*.cs" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0-linux' ">
	<Compile Include="Platforms\Linux\*.cs" />
</ItemGroup>

Thank you in advance. 😊

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions