Beispiel #1
0
        AssemblyDefinition GetAssemblyInGac(AssemblyNameReference reference)
        {
            if (reference.PublicKeyToken == null || reference.PublicKeyToken.Length == 0)
            {
                return(null);
            }

            if (OnMono())
            {
                foreach (string gacpath in MonoGacPaths)
                {
                    string s = GetAssemblyFile(reference, gacpath);
                    if (File.Exists(s))
                    {
                        return(AssemblyFactory.GetAssembly(s));
                    }
                }
            }
            else
            {
                string currentGac = GetCurrentGacPath();
                if (currentGac == null)
                {
                    return(null);
                }

                string [] gacs = new string [] { "GAC_MSIL", "GAC_32", "GAC" };
                for (int i = 0; i < gacs.Length; i++)
                {
                    string gac = Path.Combine(Directory.GetParent(currentGac).FullName, gacs [i]);
                    string asm = GetAssemblyFile(reference, gac);
                    if (Directory.Exists(gac) && File.Exists(asm))
                    {
                        return(AssemblyFactory.GetAssembly(asm));
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        static AssemblyDefinition GetCorlib(AssemblyNameReference reference)
        {
            SR.AssemblyName corlib = typeof(object).Assembly.GetName();
            if (corlib.Version == reference.Version || IsZero(reference.Version))
            {
                return(AssemblyFactory.GetAssembly(typeof(object).Module.FullyQualifiedName));
            }

            string path = Directory.GetParent(
                Directory.GetParent(
                    typeof(object).Module.FullyQualifiedName).FullName
                ).FullName;

            string runtime_path = null;

            if (OnMono())
            {
                if (reference.Version.Major == 1)
                {
                    runtime_path = "1.0";
                }
                else if (reference.Version.Major == 2)
                {
                    if (reference.Version.Minor == 1)
                    {
                        runtime_path = "2.1";
                    }
                    else
                    {
                        runtime_path = "2.0";
                    }
                }
                else if (reference.Version.Major == 4)
                {
                    runtime_path = "4.0";
                }
            }
            else
            {
                switch (reference.Version.ToString())
                {
                case "1.0.3300.0":
                    runtime_path = "v1.0.3705";
                    break;

                case "1.0.5000.0":
                    runtime_path = "v1.1.4322";
                    break;

                case "2.0.0.0":
                    runtime_path = "v2.0.50727";
                    break;

                case "4.0.0.0":
                    runtime_path = "v4.0.30319";
                    break;
                }
            }

            if (runtime_path == null)
            {
                throw new NotSupportedException("Version not supported: " + reference.Version);
            }

            path = Path.Combine(path, runtime_path);

            if (File.Exists(Path.Combine(path, "mscorlib.dll")))
            {
                return(AssemblyFactory.GetAssembly(Path.Combine(path, "mscorlib.dll")));
            }

            return(null);
        }