question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Analyzers flow from dependency into referencing project

See original GitHub issue

If 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:open
  • Created 7 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
nguerreracommented, Aug 3, 2018

@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:

    <PackageReference Include="Analyzers" Version="1.2.3" PrivateAssets="All" />

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, if PrivateAssets 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", but analyzers do flow by default unlike contentfiles and build.

1reaction
tdwrightcommented, Dec 10, 2018

@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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found