How to include/exclude platform dependent code

Copper Contributor

Im wondering what the strategy is for inclusion/exclusion of code depending on TargetFramework? Or is there one?

Eg, in ...\Core\src\Handlers\Application\ApplicationHandler.cs, it uses both file inclusion/exclusion and #if statements to include/exclude code.

I've temporally removed the #if and added the appropriate lines to the platform's files, which were already there by the way. It compiles and works ok.

By having it in both places one has to look all over the place to find/debug code.

It seems to me that file inclusion/exclusion is the most appropriate place to put platform dependent code.

2 Replies
You can use multi targeting like approch, you set build env variables like TARGET_PLATFORM and in your csproj you make something like that

<ItemGroup Condition="'$(TARGET_PLATFORM)' == 'Linux'">
<Compile Include="*.linux.cs" />
</ItemGroup>

@vodevil1985, i know this. however my query was you have too ways of including/excluding code, what is the best to use? What you have said or #if defined.