Getting the PublicKeyToken of .Net assemblies

前端 未结 13 1038
忘掉有多难
忘掉有多难 2020-11-30 16:57

What is the simplest way to find the Public-Key-Token of an assembly?

The simplest way I can think of would be a simple right-click, get public key, but this functio

相关标签:
13条回答
  • 2020-11-30 17:39

    If the library is included in the VS project, you can check .cproj file, e.g.:

    <ItemGroup>
        <Reference Include="Microsoft.Dynamic, Version=1.1.0.20, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
    ...
    
    0 讨论(0)
  • 2020-11-30 17:39

    If you have included the assembly in your project, you can do :

                var assemblies =
                    AppDomain.CurrentDomain.GetAssemblies();
    
    
                foreach (var assem in assemblies)
                {
                        Console.WriteLine(assem.FullName);
                }
    
    0 讨论(0)
  • 2020-11-30 17:40

    Another options is to use the open source tool NuGet Package Explorer for this.

    From a Nuget package (.nupkg) you could check the PublicKeyToken, or drag the binary (.dll) in the tool. For the latter select first "File -> new"

    0 讨论(0)
  • 2020-11-30 17:42

    The simplest way for me is to use ILSpy.

    When you drag & drop the assembly on its window and select the dropped assembly on the the left, you can see the public key token on the right side of the window.

    (I also think that the newer versions will also display the public key of the signature, if you ever need that one... See here: https://github.com/icsharpcode/ILSpy/issues/610#issuecomment-111189234. Good stuff! ;))

    0 讨论(0)
  • 2020-11-30 17:42

    You can use the Ildasm.exe (IL Disassembler) to examine the assembly's metadata, which contains the fully qualified name.

    Following MSDN: https://msdn.microsoft.com/en-us/library/2exyydhb(v=vs.110).aspx

    0 讨论(0)
  • 2020-11-30 17:48

    another option:

    if you use PowerShell, you can find out like:

    PS C:\Users\Pravat> ([system.reflection.assembly]::loadfile("C:\Program Files (x86)\MySQL\Connector NET 6.6.5\Assemblies\v4.0\MySql.Data.dll")).FullName
    

    like

    PS C:\Users\Pravat> ([system.reflection.assembly]::loadfile("dll full path")).FullName
    

    and will appear like

    MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d

    0 讨论(0)
提交回复
热议问题