C
C#15mo 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_FOP15mo ago
thank you!
reflectronic
reflectronic15mo 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_FOP15mo 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
reflectronic15mo ago
what is the API
David_F
David_FOP15mo ago
Stopwatch.GetElapsedTime
333fred
333fred15mo 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_FOP15mo ago
thanks
Accord
Accord15mo 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.
Want results from more Discord servers?
Add your server