How do I find the PublicKeyToken for a particular dll?

后端 未结 10 625
后悔当初
后悔当初 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

    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

提交回复
热议问题