Last active
July 28, 2020 14:57
-
-
Save johnallers/8cb5173a4b0adf1d0bf2 to your computer and use it in GitHub Desktop.
FindAssemblyVersionConflicts
This file contains 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; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Reflection; | |
namespace FindAssemblyVersionConflicts | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
if (args.Length != 3) | |
{ | |
Console.WriteLine("FindAssemblyVersionConflicts - Lists all dependent assemblies."); | |
Console.WriteLine("Usage: FindAssemblyVersionConflicts.exe <path> <search pattern> <dependent assembly starts with>"); | |
Console.WriteLine("Example: FindAssemblyVersionConflicts.exe . Thycotic*.dll Thycotic"); | |
return; | |
} | |
string path = args[0]; | |
string searchPattern = args[1]; | |
string dependentAssemblyStartsWith = args[2]; | |
var list = new List<Tuple<string, string>>(); | |
var allAssemblies = System.IO.Directory.GetFiles(path, searchPattern, SearchOption.AllDirectories); | |
foreach (var assemblyPath in allAssemblies) | |
{ | |
try | |
{ | |
var loadedAssembly = Assembly.ReflectionOnlyLoadFrom(assemblyPath); | |
var referencedAssemblies = loadedAssembly.GetReferencedAssemblies(); | |
foreach (var refAssembly in referencedAssemblies) | |
{ | |
if (refAssembly.FullName.StartsWith(dependentAssemblyStartsWith)) | |
{ | |
list.Add(Tuple.Create(refAssembly.FullName, loadedAssembly.FullName)); | |
} | |
} | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Failed to load '{0}': {1}", assemblyPath, e.Message); | |
} | |
} | |
Console.WriteLine("============"); | |
Console.WriteLine("Dependencies"); | |
Console.WriteLine("============"); | |
var grouped = list.GroupBy(t => t.Item1); | |
foreach (var group in grouped.OrderBy(g => g.Key)) | |
{ | |
Console.WriteLine(); | |
Console.WriteLine("{0}", group.Key); | |
foreach (var i in group.OrderBy(g => g.Item2)) | |
{ | |
Console.WriteLine("\t{0}", i.Item2); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment