Define a platform-agnostic NET preprocessor symbol
See original GitHub issueIs your feature request related to a problem? Please describe.
Before .Net 6 days, if I wanted to multitarget to different platforms and split code between them, I could do it with:
#if NETSTANDARD
- platform-agnostic code (usuallythrow new PlatformNotSupported
or something)#if ANDROID
- platform-spesific implementation
Now, if I target net6.0;net6.0-android;net6.0-ios
, I can still do #if ANDROID
(or #if NET6_0_ANDROID_OR_GREATER
), but there’s no symbol to check that current TFM is net6.0
(platform-agnostic) like NETSTANDARD
, since both NET
and NET6_0
are also defined in platform-spesific TFMs.
Describe the solution you’d like
Define a new preprocessor symbol that would indicate platform-agnostic TMF
Workaround
<PropertyGroup Condition=" !$(TargetFramework.Contains('-')) ">
<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
</PropertyGroup>
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:24 (13 by maintainers)
Top Results From Across the Web
c# - Preprocessor symbol for Net without platform
I'm working with Xamarin/MAUI prjects. Previously if I wanted to do a preprocessor check for platform-independant code, I could do #if ...
Read more >C# preprocessor directives
Learn the different C# preprocessor directives that control conditional compilation, warnings, nullable analysis, and more.
Read more >Multi-Targeting and Porting a .NET Library to .NET Core 2.0
I've been holding off porting any of my full frameworks to .NET Core. With the latest .NET Core 2.0 and .NET Standard 2.0...
Read more >C# preprocessor directive symbols from the dotnet build ...
Invoking the C# compiler directly allows one to pass in symbols for the preprocessor via a command option (-define or -d).
Read more >C preprocessor - Wikipedia
The C preprocessor is the macro preprocessor for several computer programming languages, such as C, Objective-C, C++, and a variety of Fortran languages....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As a design note, not all .NET SDK languages support partial classes (and as a result the multiple files with platform-specific code in each pattern), and so they would be using code like the samples @maxkoshevoi put forth. For that reason having a symbol could help cut down on the noise in a file. What about
NET_ANY
, keeping in line with theNET_<OS Platform>
pattern so far?Maybe the opposite is fine too?
Define
NET_PLATFORM
only on the platforms so if I wat a net6.0 only, then I do!NET_PLATFORM