✅ How to check user's target framework moniker in my source generator?
I'm using
IIncrementalGenerator
. I want to generate different code for the user based on his project .NET version as newer .NET APIs are available only since some version.8 Replies
thank you!
this is the wrong way to approach this
the better way is to check if the APIs exist before using them
I went with conditional compilation based on TFM
there is no way .NET is going to remove a method once they introduced it as generally available
what is the API
Stopwatch.GetElapsedTime
Don't anyway
Make your generator conditional on whether the api exists, not on the tfm
The compiler has no concept of tfm. We don't know what version of dotnet you're targeting. We know what apis are available because your references bring them in
thanks
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.