dotnet/roslyn-sdk

[Question] Roslyn analyzer targeting net6.0 not working.

chandlerlims opened this issue · 3 comments

I've created a Roslyn analyzer with target framework net6.0. My consuming project is also targeting the same framework.
but the analyzer doesn't seem to work.
some articles (e.g. https://www.meziantou.net/multi-targeting-a-roslyn-analyzer.htm) states that analyzer must target netstandard2.0.
If I switch back to netstandard2.0 everything works fine.

Can anyone explain the reason behinds that?

The analyzer runs in the compiler process, which is separate from the process of the project using the source generator. Since the compiler sometimes runs in .NET Framework (e.g. inside Visual Studio) and other times runs in .NET Core (e.g. in dotnet build), the analyzer needs to target netstandard2.0 to work consistently across these.

@sharwell a follow-up question: if Visual Studio starts to run on .net core, then will Roslyn be able to be targeted to .net6 (or higher version)? Is this on the roadmap?

Today it's a hypothetical scenario, but it's on a list of "things to make a decision on if Visual Studio runs on .NET [Core]"