Skip to content

Instantly share code, notes, and snippets.

@chriseldredge
Created March 4, 2022 13:29
Show Gist options
  • Save chriseldredge/bab768c275f08b98ff90b722b40bcab6 to your computer and use it in GitHub Desktop.
Save chriseldredge/bab768c275f08b98ff90b722b40bcab6 to your computer and use it in GitHub Desktop.
Toy c# app to dump assembly version and type info
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
public class AssemblyVersion
{
public static void Main(string[] args)
{
IEnumerable<string> paths = args;
var verbose = false;
var dumpTypes = false;
for (var i=0; i<args.Length && args[i].StartsWith("-"); i++) {
paths = paths.Skip(1);
switch (args[i]) {
case "-v":
verbose = true;
break;
case "-t":
dumpTypes = true;
break;
default:
Console.Error.WriteLine("Unrecognized option " + args[i]);
break;
}
}
foreach (var path in paths) {
try {
var asm = Assembly.LoadFrom(path);
Console.Write(path + ": " + asm.FullName);
var infoVersion = (AssemblyInformationalVersionAttribute)asm.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false).FirstOrDefault();
if (verbose && infoVersion != null)
{
Console.Write(" (product version: {0})", infoVersion.InformationalVersion);
}
Console.WriteLine();
if (verbose && asm.GetName().GetPublicKey() != null && asm.GetName().GetPublicKey().Length > 0) {
Console.Write("public key: ");
var pubkey = asm.GetName().GetPublicKey();
for (int i=0;i<pubkey.GetLength(0);i++) {
Console.Write ("{0:x2}", pubkey[i]);
}
Console.WriteLine();
}
if (verbose) {
foreach (var reference in asm.GetReferencedAssemblies()) {
Console.WriteLine("\treference: " + reference.FullName);
}
}
if (dumpTypes) {
foreach (var type in asm.GetTypes()) {
Console.WriteLine("\ttype: " + type);
}
}
} catch (Exception e) {
while (e != null) {
Console.Error.WriteLine(e.Message);
e = e.InnerException;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment