C
C#9mo ago
David_F

✅ 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
David_F
David_F9mo ago
thank you!
reflectronic
reflectronic9mo ago
this is the wrong way to approach this the better way is to check if the APIs exist before using them
David_F
David_F9mo ago
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
reflectronic
reflectronic9mo ago
what is the API
David_F
David_F9mo ago
Stopwatch.GetElapsedTime
333fred
333fred9mo ago
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
David_F
David_F9mo ago
thanks
Accord
Accord9mo ago
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.