If we define <TargetFrameworks>
in the .csproj like
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net6.0-windows</TargetFrameworks>
</PropertyGroup>
I can define different dependency packages like
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
...
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0-windows'">
...
</ItemGroup>
And check in the code with precompiler statements to use different library (version) features
#if (NETSTANDARD2_0)
#endif
#if (NET6_0)
#endift
Works …
But how do I check explicitly for target framework net6.0-windows?
(Unfortunatly) I need differences between Net6.0 and Net6.0-windows.
You may find #if WINDOWS
, or #if WINDOWS && NET6_0
work for your needs (maybe consider NET6_0_OR_GREATER
, note); otherwise, you can define your own symbol:
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0-windows'">
<DefineConstants>$(DefineConstants);YOUR_THING</DefineConstants>
</ItemGroup>
and use #if YOUR_THING