Exemplo n.º 1
0
        string GetGacFile(string aname, bool allowPartialMatch)
        {
            // Look for the assembly in the GAC.

            string name, version, culture, token;

            ParseAssemblyName(aname, out name, out version, out culture, out token);
            if (name == null)
            {
                return(null);
            }

            if (!allowPartialMatch)
            {
                if (name == null || version == null || culture == null || token == null)
                {
                    return(null);
                }

                foreach (string gacDir in runtime.GetGacDirectories())
                {
                    string file = Path.Combine(gacDir, name);
                    file = Path.Combine(file, version + "_" + culture + "_" + token);
                    file = Path.Combine(file, name + ".dll");
                    if (File.Exists(file))
                    {
                        return(file);
                    }
                }
            }
            else
            {
                string pattern = (version ?? "*") + "_" + (culture ?? "*") + "_" + (token ?? "*");
                foreach (string gacDir in runtime.GetGacDirectories())
                {
                    string asmDir = Path.Combine(gacDir, name);
                    if (Directory.Exists(asmDir))
                    {
                        foreach (string dir in Directory.GetDirectories(asmDir, pattern))
                        {
                            string file = Path.Combine(dir, name + ".dll");
                            if (File.Exists(file))
                            {
                                return(file);
                            }
                            file = Path.Combine(dir, name + ".exe");
                            if (File.Exists(file))
                            {
                                return(file);
                            }
                        }
                    }
                }
            }
            return(null);
        }