Analyzers flow from dependency into referencing project
See original GitHub issueIf you have a project set up as follows
- Sln
|-- ProjectA
|-- ProjectB
And add an analyzer to ProjectA
, and then reference ProjectA
in ProjectB
, ProjectB
also ends up having the analyzer run. Is this expected? Is there a way to turn this off for solutions where ProjectB
does not want the analyzer to be run?
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Dependencies analysis | IntelliJ IDEA Documentation
In IntelliJ IDEA, you can visualize dependencies between the parts of a project (modules, classes, and so on) and highlight the information ...
Read more >PackageReference in project files - NuGet
Add a dependency in your project file using the following syntax: ... and analyzers will flow to the parent project--> <PackageReference ...
Read more >Explore project dependency diagram - ReSharper
Build the dependency diagram based on the project references. This step is done automatically when you open the diagram and it takes almost...
Read more >Analyzing Dependencies and References
The Dependency Visualizer provides graphical visuals of all the direct and indirect dependencies and references for an application.
Read more >How can I reference a nuget package that contains a ...
How can I reference a nuget package that contains a dependency on static code analyzers without introducing those analyzers into downstream ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sharwell observed that
PrivateAssets="all"
does actually work around the issue in many cases. So I took a deeper look, and it turns out that is a reasonable workaround for a common case where the analyzers come from a package with no other assets that you need to flow to consumers.Consider the Project Caller -> Project Callee -> Package Analyzers
If Callee.csproj has:
Then Analyzers will not be picked up by project B.
However, if a package has a mix of of both analyzers and API, then you cannot block the analyzers without also blocking the API from flowing. The reason for this is that when
PrivateAssets="All"
, then NuGet will not write out the package and its list of"files"
in the"libraries"
section of Caller’s project.assets.json. However, ifPrivateAssets
is anything else, then it will write them. For non-analyzer assets, these"files"
don’t matter, it is the"compile"
,"runtime"
lists under"targets"
that do. But there is no such section for"analyzers"
under"targets"
(NuGet/Home#6279) and so the SDK uses"files"
under"libraries"
, which leads to this behavior.The irony remains that the default value of
PrivateAssets
is"contentfiles;analyzers;build"
, butanalyzers
do flow by default unlikecontentfiles
andbuild
.@nguerrera Thanks for that workaround. Got me out of a pickle.
What’s the status of a proper fix? Is this something for which contributions would be welcome?