Skip to content

Instantly share code, notes, and snippets.

@nycdotnet
Last active July 14, 2025 20:44
Show Gist options
  • Select an option

  • Save nycdotnet/e4ccccaa9f9ab21d021e039b9a0e7f7b to your computer and use it in GitHub Desktop.

Select an option

Save nycdotnet/e4ccccaa9f9ab21d021e039b9a0e7f7b to your computer and use it in GitHub Desktop.
Program to inventory real .NET DLL versions
using System.Reflection;
namespace BindingRedirectHelper;
// I am a .NET 8+ console app.
internal class Program
{
static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("Provide a path to the bin folder of your .NET application as the argument.");
return;
}
var files = Directory.GetFiles(args[0]);
foreach (var fileName in files)
{
if (!(fileName.EndsWith(".dll") || fileName.EndsWith(".exe")))
{
continue;
}
try
{
var version = Assembly.LoadFile(fileName)?.GetName()?.Version?.ToString();
Console.WriteLine($"{fileName}\t{version}");
}
catch (BadImageFormatException)
{
// Not a .NET assembly, skip it.
Console.WriteLine($"{fileName}\tNot .NET");
continue;
}
catch (FileLoadException fle)
{
Console.WriteLine($"Failed to load {fileName}: {fle.Message}");
continue;
}
catch (Exception ex)
{
Console.WriteLine($"Unexpected error loading {fileName}: {ex.Message}");
continue;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment