phmonte / Buildalyzer

A utility to perform design-time builds of .NET projects without having to think too hard about it.
MIT License
593 stars 94 forks source link

Resolve transitive packages? #135

Open chucker opened 4 years ago

chucker commented 4 years ago

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:

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?

daveaglick commented 4 years ago

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.

chucker commented 4 years ago

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.)

daveaglick commented 4 years ago

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: