dotnet / roslyn-analyzers

MIT License
1.58k stars 464 forks source link

Roslyn plugins (analyzers, source generators) target .NET 8 instead of .NET Standard 2.0 #7302

Closed Sybren- closed 3 months ago

Sybren- commented 5 months ago

I'm trying to reference a .net 8.0 project but the Roslyn analyzer requires .netstandard 2.0 which makes this not possible.

Similar issue: https://developercommunity.visualstudio.com/t/Please-enable-Roslyn-plugins-analyzers/10616185?space=41&sort=newest

As far as I can find out it is not possible to reference .net 8 projects from the analyzer?

CollinAlpert commented 4 months ago

Could you give a more concrete example on what you are trying to achieve and why the referenced project needs to be a net8.0 instead of a netstandard2.0 project?

Sybren- commented 4 months ago

I'm trying to reference a net8.0 project (by project reference) from my analyzer. This requires that my analyzer targets net8.0 instead of .netcore 3.1. The referenced project is net8.0 because this is the latest version.

The upgrade of the analyzer requires that the other projects are updated too (CodeFixes, Package, Test. VSIX). I upgraded all projects and managed to get them building, but when I add the analyzer nuget package to a project and start the code analysis, nothing happens (no errors).

CollinAlpert commented 3 months ago

There are multiple issues on this matter already, e.g. https://github.com/dotnet/roslyn/issues/47087 and https://github.com/dotnet/roslyn/issues/45162, so unfortunately targeting net8.0 from a Roslyn component is not possible right now.

sharwell commented 3 months ago

This is effectively a duplicate of #45162.

The referenced project is net8.0 because this is the latest version.

Many cases where we have seen this in the past, the analyzer did not need to reference the project at all, and removing the reference resolved the matter. For remaining cases, the referenced project can multi-target netstandard2.0 and net8.0 to support both scenarios it is being used for.