Last active
July 14, 2025 20:44
-
-
Save nycdotnet/e4ccccaa9f9ab21d021e039b9a0e7f7b to your computer and use it in GitHub Desktop.
Program to inventory real .NET DLL versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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