在GAC枚举集 [英] enumerating assemblies in GAC

查看:209
本文介绍了在GAC枚举集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能枚举GAC所有可用的组件在C#?

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

其实我现在面临的问题与一个愚蠢的code - 所谓Telerik.Web.UI.dll大会被称为在项目中使用 - 这个特殊的DLL是不是在BIN文件夹present。和应用工作在服务器上很好 - 但我的机器上,显然编译器是给错误。前开发商坚持认为,它是不是在GAC在服务器上,这是它是什么。现在,我需要检查这个DLL是否被注册在GAC或没有。

Actually I am facing an issue with a stupid code - the assembly called Telerik.Web.UI.dll is referred and used in project - this particular DLL is not present in BIN folder. And application is working fine on the server - but on my machine, obviously compiler is giving error. Ex-Developer insists that it is not in GAC on the server and 'it is what it is'. Now I need to check whether this DLL is registered in GAC or not.

帮助将AP preciated。

Help will be appreciated.

美好的一天;

推荐答案

如果您已限制对服务器的访问,然后这可能工作:

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<string> gacFolders = new List<string>() { 
    "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("<hr/>" + folder + "<hr/>");

        string[] assemblyFolders = Directory.GetDirectories(path);
        foreach (string assemblyFolder in assemblyFolders)
        {
            Response.Write(assemblyFolder + "<br/>");
        }
    }
}

它基本上列举的原始GAC文件夹。它适用于DiscountASP共同主办所以可能适用于您的托管环境。

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.

这篇关于在GAC枚举集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆