Buildalyzer icon indicating copy to clipboard operation
Buildalyzer copied to clipboard

Resolve transitive packages?

Open chucker opened this issue 5 years ago • 3 comments

I use Buildalyzer (and various other libraries) to check the state of a csproj. One of the steps is to add two package references if needed, where "needed" means:

  • the packages need to be referenced at all, and
  • in a version at least as high as the one I want

I can ask Buildalyzer for the existing package references and see if they're already in there, but one weakness in that approach is that it can still lead to "detected package downgrade" warnings, because there might be a different package reference that implicitly gets a newer version.

Is there any way to have Buildalyzer give me a flat list (or tree would be OK, too) of all package references including transitive ones? I assume this would involve invoking a design-time build, parsing project.assets.json or similar?

chucker avatar Apr 29 '20 07:04 chucker

I assume this would involve invoking a design-time build, parsing project.assets.json or similar?

Exactly right - that data isn't surfaced directly by MSBuild so Buildalyzer doesn't have access to it. However, @mholo65 has done all the heavy lifting to do exactly this. If you just need out-of-band access to the full dependency graph, depends is an awesome tool. Otherwise, you can take a look at the code in https://github.com/mholo65/depends/blob/master/src/Depends.Core/DependencyAnalyzer.cs and see how it does it.

daveaglick avatar May 01 '20 15:05 daveaglick

If you just need out-of-band access to the full dependency graph

Ideally, I would want something like DependencyGraph.Packages.Any(p => p.PackageID == packageID && p.Version >= version). (Depending on which I would run different code generation steps.)

depends is an awesome tool. Otherwise, you can take a look at the code in https://github.com/mholo65/depends/blob/master/src/Depends.Core/DependencyAnalyzer.cs and see how it does it.

Thanks a bunch for the pointer!

I assume that means you consider this kind of functionality outside the scope of Buildalyzer? (Which, fair enough.)

chucker avatar May 04 '20 10:05 chucker

I assume that means you consider this kind of functionality outside the scope of Buildalyzer?

Yeah, probably. I have to constantly fight the urge to add all kinds of extra functionality - there's a lot that could be done after the build, but it's hard enough keeping everything up to date with MSBuild and incrementing project types and versions. Might make a cool third-party extension though :wink:

daveaglick avatar May 04 '20 22:05 daveaglick