Based on "thou shalt not report diagnostics from source generators" (a rule the Roslyn team wrote down, but I somehow missed), I've been moving all the diagnostics over to the analyzers project. This is somewhat tedious, but it has the advantage that these rules typically apply to non-AOT projects, so everybody wins from more rules (and these are all errors, so really everybody wins at seeing problems because you even try to run your tests).
I'm not writing any fixers, but I'm sure some of them will be easy to write and for someone to come in and fill in later, if they're looking to dabble in the world of source analysis.

Hmm, just hit the first analyzer that needs relatively new version of Roslyn because of a new language feature I need to support (collection expression syntax) and now I'm not sure what to do. The existing analyzers target Roslyn 3.11 to support VS2019 16.11, which is very much not capable of running that. We'll need Roslyn 4.8, with a minimum supported VS version of 2022 17.8.

Time to bump up the minimum? What happens if I try to run Roslyn 4.8 analyzers in 2019? đŸ€”

#DotNet #Roslyn #Analyzers

Hmm, I'm wrong. This is the _second_ analyzer that's trying to use collection expression support, and I just wasn't paying close enough attention previously.

Thankfully, the early poll results seem to indicate that it won't be a problem to bump up to 4.8. https://dotnet.social/@xunit/116350131334850506

xUnit.net (@[email protected])

What version of Visual Studio are you using with xUnit.net? [ ] VS 2019 [ ] VS 2022 (< 17.8) [ ] VS 2022 (>= 17.8) [ ] VS 2026

dotnet.social
@bradwilson If necessary, you can multi-target the analyzer. It does make the packaging a bit more complex, though:
https://www.meziantou.net/roslyn-analyzers-how-to.htm#support-multiple-ver
Roslyn analyzers: How to - Gérald Barré

In this post, I share some resources to help you write Roslyn analyzers

Meziantou's blog
@meziantou There's no point if nobody's using the old stuff. It's just maintenance burden for no benefit.
@meziantou There are APIs we're using in the old version that have known performance issues, so it would be nice to just dump 3.11 entirely.
@bradwilson I recently dropped support for Roslyn 3.x in Meziantou.Analyzer and didn’t get any complaints, so I assume it’s safe now 😉