dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.22k stars 1.35k forks source link

Unify filtering of unnecessary analyzer nodes with the Roslyn logic #5849

Open jasonmalinowski opened 3 years ago

jasonmalinowski commented 3 years ago

For the legacy project system, Roslyn has logic to avoid showing analyzer nodes in certain cases to keep the list smaller. In our CPS project system, these nodes are made by this code in this repo but there is no equivalent filtering.

The current Roslyn code (warning: it's being tweaked a bit for generators) is visible here: https://github.com/dotnet/roslyn/blob/d8eb54d3c56f3b8415eb713b94759bce085e13c7/src/VisualStudio/Core/Impl/SolutionExplorer/AnalyzerItem/AnalyzerItemSource.cs#L209

jasonmalinowski commented 3 years ago

(filed per the comment on https://github.com/dotnet/roslyn/pull/49050/files/4c15723d73ae5558f1d724d511ba5411b5c72157#r514497891)

davkean commented 3 years ago

We attempted to do this in past, but I thought we were missing the right APIs and ended up needing to duplicate the logic of loading/finding analyzers, which is a bit problematic. Is there now an API that we can consume?

jasonmalinowski commented 3 years ago

It's unclear to me; it looks like the only internal bit is the dealing with analyzers with load errors, which is also conveniently commented out. So... ¯_(ツ)_/¯

drewnoakes commented 3 years ago

Currently the top-level analyzer nodes are populated based on the results of target CollectAnalyzersDesignTime defined here:

https://github.com/dotnet/project-system/blob/841f24f5ed628f5d32c88a030b9ce21f6225b589/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/DesignTimeTargets/Microsoft.Managed.DesignTime.targets#L370-L371

The dependencies tree shouldn't have logic about specific types of dependency. Can we move any filtering logic to the SDK or MSBuild?

jasonmalinowski commented 3 years ago

We could move it to MSBuild, although I think we'd have to write another build task for that.

drewnoakes commented 3 years ago

MSBuild seems like the right place for this.

No Project System changes would be required. Should this issue be transferred, and if so to whom?

jasonmalinowski commented 3 years ago

What would the filtering logic have to look like? Are we adding metadata to the items or doing something else?

jasonmalinowski commented 3 years ago

Also, which MSBuild targets files would the changes have to go in?