Skip to content

Instantly share code, notes, and snippets.

Last active Sep 12, 2016
What would you like to do?
Creates a nuget package dependency graph in graphviz dot language
# put the output in the box here:
RESULT_FILE="" # the output file
NAME_MATCH='Microsoft\.' # leave this as a blank string if you want no filtering
echo '' > $RESULT_FILE # clear out the file
echo 'digraph Dependencies {' >> $RESULT_FILE
echo ' rankdir=LR;' >> $RESULT_FILE # we want a left to right graph, as it's a little easier to read
# find all packages.config, recursively beaneath the path passed into the script
find $1 -iname packages.config | while read line; do
# find any csproj file next to the packages.config
project_path="$(dirname $line)/*.csproj"
# check it exists (e.g. to not error on a /.nuget/packages.config path)
if [ -f $project_path ]; then
# find the name of the assembly
# (our projects are not named with the company prefix, but the assemblies/packages are)
asm_name=$(grep -oP '<RootNamespace>\K(.*)(?=<)' $project_path)
# Ignore any tests projects (optional)
if [[ ${line} != *"Tests"* ]]; then
# find all lines in the packages.config where the package name has a prefix
grep -Po "package id=\"\K($NAME_MATCH.*?)(?=\")" $line | while read package; do
# write it to the result
echo " \"$asm_name\" -> \"$package\"" >> $RESULT_FILE
echo '}' >> $RESULT_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment