question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Define a platform-agnostic NET preprocessor symbol

See original GitHub issue

Is 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 (usually throw 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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:24 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
baronfelcommented, Jan 10, 2022

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 the NET_<OS Platform> pattern so far?

1reaction
mattleibowcommented, May 12, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found