Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting the full name of an assembly

Suppose I want to display the full name of an assembly, given only a path to the assembly file.

I know I could write a command line program or powershell script easily enough, but does the runtime include a command that I could use? (I've seen gacutil do it for assemblies that are in the gac, but about assemblies that are not registered?)

like image 491
JMarsch Avatar asked Sep 08 '11 20:09

JMarsch


2 Answers

I think you're looking for System.Reflection.AssemblyName.GetAssemblyName:

AssemblyName name = AssemblyName.GetAssemblyName(@"C:\path\assembly.dll");
Console.WriteLine(name.FullName);

Unlike the solution using Assembly.Load, this will not load the assembly into your AppDomain. This will allow you to get the AssemblyName for an assembly without having to resolve any references that assembly has, and without executing any code (e.g. module static constructors) in the assembly. It will even let you get the AssemblyName of an assembly that targets a version of the .NET Framework that differs from the version on which your application is running.

like image 181
Orion Avatar answered Nov 02 '22 22:11

Orion


The main problematic part of a full-name is usually the public key token. You can obtain it by entering this into the Visual Studio Command Prompt Window:

sn -T path\to\your.dll

Personally, I find it easier just to load the dll into reflector, though. That shows the full name in the bottom panel.

like image 44
Marc Gravell Avatar answered Nov 03 '22 00:11

Marc Gravell