Can anyone recommend a tool (ideally FOSS) that can analyse an .NET assembly and list its dependencies?
What I am after is a tool that given a .NET exe file can produce a report showing me the .NET assemblies (name, version, strong name, location/GAC) its is linked to; in order to assist diagnosis when a deployment fails and the application wont run.
The fuse-log viewer helps do this when its already gone wrong but its a bit clunky. I would rather be able to analyse the assembly pro-actively and see what it will need at runtime so I can validate they are present. I have looked at various reflector tools, but whist these list classes in all the linked assemblies, and names non of them seem to indicate strong names, versions etc.
Resolution
Thankyou all for the very useful feedback. Whilst ILDASM provides what I need for free (and I should have remembered that) its not very elegant in use when all you want is application "x.exe"'s dependancies.
.NET Reflector is not free anymore and neither is NDepend (for my usage terms) so those had to be rejected.
So I have created what is possibly the world's simplest console application which takes a filename and prints the dependancy names and verions based on Arve's answer which is quite suffient for my needs.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
namespace AssemblyDependencyViewer
{
class Program
{
static void Main(string[] args)
{
if (File.Exists(args[0]))
{
DumpFileReferences(args[0]);
}
else
{
var dir = new DirectoryInfo(args[0]);
if (dir.Exists)
{
var files = dir.GetFiles()
.Where((s) =>
{
return (s.Extension == ".exe") || (s.Extension == ".dll");
})
.OrderBy((s2) =>
{
return s2.Name;
})
;
foreach (var file in files)
{
Console.WriteLine(string.Format("=== File {0} ====", file.FullName));
DumpFileReferences(file.FullName);
}
}
}
Console.ReadKey(false);
}
private static void DumpFileReferences(string fileName)
{
try
{
var assembly = Assembly.ReflectionOnlyLoadFrom(fileName);
var refs = assembly.GetReferencedAssemblies();
foreach (var x in refs.OrderBy((s) =>
{
return s.Name;
}))
{
PrintFilename(x);
}
}
catch (BadImageFormatException bif)
{
Console.WriteLine(bif.Message);
}
catch (FileLoadException fl)
{
Console.WriteLine(fl.Message);
}
}
private static void PrintFilename(AssemblyName x)
{
if (x.Name.StartsWith("Apdcomms"))
{
Console.ForegroundColor = ConsoleColor.Magenta;
}
Console.WriteLine(string.Format("{1,-10} {0}", x.Name, x.Version));
Console.ResetColor();
}
}
}