Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
datoml opened this issue Dec 10, 2020 · 0 comments
Open

Comments

@datoml
Copy link

datoml commented Dec 10, 2020

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. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant