Exemplo n.º 1
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);
        }