enumerating assemblies in GAC

后端 未结 8 1862
故里飘歌
故里飘歌 2020-12-05 16:14

How can I enumerate all available assemblies in GAC in C#?

Actually I am facing an issue with a stupid code - the assembly called Telerik.Web.UI.dll is referred and

8条回答
  •  难免孤独
    2020-12-05 16:22

    If you have limited access to the server then this might work:

    // List of all the different types of GAC folders for both 32bit and 64bit
    // environments.
    List gacFolders = new List() { 
        "GAC", "GAC_32", "GAC_64", "GAC_MSIL", 
        "NativeImages_v2.0.50727_32", 
        "NativeImages_v2.0.50727_64",
        "NativeImages_v4.0.30319_32",
        "NativeImages_v4.0.30319_64"
    };
    
    foreach (string folder in gacFolders)
    {
        string path = Path.Combine(
           Environment.ExpandEnvironmentVariables(@"%systemroot%\assembly"), 
           folder);
    
        if(Directory.Exists(path))
        {
            Response.Write("
    " + folder + "
    "); string[] assemblyFolders = Directory.GetDirectories(path); foreach (string assemblyFolder in assemblyFolders) { Response.Write(assemblyFolder + "
    "); } } }

    It basically enumerates the raw GAC folders. It works on DiscountASP shared hosting so might work for your hosting environment.

    It could be embellished by enumerating deeper into each assembly's folder to yank out the version number and public key token.

提交回复
热议问题