How do I find the PublicKeyToken for a particular dll?

后端 未结 10 602
后悔当初
后悔当初 2020-12-04 06:10

I need to recreate a provider in my web.config file that looks something like this:


  

        
相关标签:
10条回答
  • 2020-12-04 06:23

    sn -T <assembly> in Visual Studio command line. If an assembly is installed in the global assembly cache, it's easier to go to C:\Windows\assembly and find it in the list of GAC assemblies.

    On your specific case, you might be mixing type full name with assembly reference, you might want to take a look at MSDN.

    0 讨论(0)
  • 2020-12-04 06:23

    As @CRice said you can use the below method to get a list of dependent assembly with publicKeyToken

    public static int DependencyInfo(string args) 
    {
        Console.WriteLine(Assembly.LoadFile(args).FullName);
        Console.WriteLine(Assembly.LoadFile(args).GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute), false).SingleOrDefault());
        try {
            var assemblies = Assembly.LoadFile(args).GetReferencedAssemblies(); 
    
            if (assemblies.GetLength(0) > 0)
            {
                foreach (var assembly in assemblies)
                {
                    Console.WriteLine(" - " + assembly.FullName + ", ProcessorArchitecture=" + assembly.ProcessorArchitecture);             
                }
                return 0;
            }
        }
        catch(Exception e) {
            Console.WriteLine("An exception occurred: {0}", e.Message);
            return 1;
        } 
        finally{}
    
        return 1;
    }
    

    i generally use it as a LinqPad script you can call it as

    DependencyInfo("@c:\MyAssembly.dll"); from the code

    0 讨论(0)
  • 2020-12-04 06:26

    You can also check by following method.

    Go to Run : type the path of DLL for which you need public key. You will find 2 files : 1. __AssemblyInfo_.ini 2. DLL file

    Open this __AssemblyInfo_.ini file in notepad , here you can see Public Key Token.

    0 讨论(0)
  • 2020-12-04 06:30

    Using sn.exe utility:

    sn -T YourAssembly.dll
    

    or loading the assembly in Reflector.

    0 讨论(0)
  • 2020-12-04 06:34

    If you have the DLL added to your project, you can open the csproj file and see the Reference tag.

    Example:

    <Reference Include="System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
    
    0 讨论(0)
  • 2020-12-04 06:37

    Using PowerShell, you can execute this statement:

    ([system.reflection.assembly]::loadfile("c:\MyDLL.dll")).FullName
    

    The output will provide the Version, Culture and PublicKeyToken as shown below:

    MyDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a
    
    0 讨论(0)
提交回复
热议问题