Gopal Chandak
Gopal Chandak

Reputation: 385

How to get the projects having a particular nuget package as reference

I have around 100 projects in my .NET solution. I managed to get all the nuget packages used in the projects through Package manager console using a simple command.

I have around 100 Nuget packages . Now for every nuget package I want the projects that are having it as a reference. i.e Suppose I have three projects A,B and C and I have Nuget package suppose nHibernate.

Manually when I go to references section of each project I see nHibernate is referenced in Project A and Project B. So my dependent project for that package is A and B.

Like this I want for all my nuget packages. How can I do this without any manual task. Like is there any command or way I can use.

Upvotes: 0

Views: 2310

Answers (2)

Tarik Tutuncu
Tarik Tutuncu

Reputation: 818

If you are using Visual Studio Enterprise you will have Microsoft Architecture Diagrams and Analysis Tools installed.

  1. From the top menu bar select Architecture then select Generate Code Map For Solution

enter image description here

  1. Expand the Externals

enter image description here

  1. From the externals list select your package and right click it and select New Graph From Selection

enter image description here

  1. A new graph will open. Right click again on the package and select Show Assemblies Referencing This

enter image description here

  1. You will get a code graph showing assemblies referencing the package. You can now save this code graph in a separate folder with the packages name for later use.

enter image description here

You can also do this for multiple packages to view all the dependencies of all packages you selected. On step 3 just select multiple packages with CTRL pressed and follow the same steps.

Upvotes: 5

Mihail Stancescu
Mihail Stancescu

Reputation: 4138

There may be a number of options you may have:

  1. Search through all the packages.config using search in files
  2. Write a small console app that loops through all the files and add them in a MultiValueDictionary with the package as the key and the values the projects that has that package.
  3. There is an node package that can output the packages used available here.
  4. There is a Nuget Package visualizer on github available here.

Going with option 2 gives you the most flexibility if you/your team has the time to write it. This may be useful in a build pipeline to check for dependencies and alert if there are inconsistencies, for example.

Upvotes: 1

Related Questions