Пример #1
0
        public void NoBuildOrMajor()
        {
            var name = new AssemblyNameReference ("Foo", new Version (0, 0));
            Assert.AreEqual ("Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", name.FullName);

            name = new AssemblyNameReference ("Foo", new Version (0, 0, 0));
            Assert.AreEqual ("Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", name.FullName);
        }
Пример #2
0
        public void ZeroVersion()
        {
            var name = new AssemblyNameReference ("Foo", null);
            Assert.AreEqual ("0.0.0.0", name.Version.ToString (fieldCount: 4));
            Assert.AreEqual ("Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", name.FullName);

            name = new AssemblyNameReference ("Foo", new Version (0, 0, 0, 0));
            Assert.AreEqual ("0.0.0.0", name.Version.ToString (fieldCount: 4));
            Assert.AreEqual ("Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", name.FullName);
        }
Пример #3
0
        public override AssemblyDefinition Resolve(AssemblyNameReference name)
        {
            if (name == null)
                throw new ArgumentNullException ("name");

            AssemblyDefinition assembly;
            if (cache.TryGetValue (name.FullName, out assembly))
                return assembly;

            assembly = base.Resolve (name);
            cache [name.FullName] = assembly;

            return assembly;
        }
Пример #4
0
        AssemblyDefinition SearchDirectory(AssemblyNameReference name, IEnumerable<string> directories, ReaderParameters parameters)
        {
            var extensions = new [] { ".exe", ".dll" };
            foreach (var directory in directories) {
                foreach (var extension in extensions) {
                    string file = Path.Combine (directory, name.Name + extension);
                    if (File.Exists (file))
                        return GetAssembly (file, parameters);
                }
            }

            return null;
        }
Пример #5
0
        AssemblyDefinition GetCorlib(AssemblyNameReference reference, ReaderParameters parameters)
        {
            var version = reference.Version;
            var corlib = typeof (object).Assembly.GetName ();

            if (corlib.Version == version || IsZero (version))
                return GetAssembly (typeof (object).Module.FullyQualifiedName, parameters);

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

            if (on_mono) {
                if (version.Major == 1)
                    path = Path.Combine (path, "1.0");
                else if (version.Major == 2) {
                    if (version.MajorRevision == 5)
                        path = Path.Combine (path, "2.1");
                    else
                        path = Path.Combine (path, "2.0");
                } else if (version.Major == 4)
                    path = Path.Combine (path, "4.0");
                else
                    throw new NotSupportedException ("Version not supported: " + version);
            } else {
                switch (version.Major) {
                case 1:
                    if (version.MajorRevision == 3300)
                        path = Path.Combine (path, "v1.0.3705");
                    else
                        path = Path.Combine (path, "v1.0.5000.0");
                    break;
                case 2:
                    path = Path.Combine (path, "v2.0.50727");
                    break;
                case 4:
                    path = Path.Combine (path, "v4.0.30319");
                    break;
                default:
                    throw new NotSupportedException ("Version not supported: " + version);
                }
            }

            var file = Path.Combine (path, "mscorlib.dll");
            if (File.Exists (file))
                return GetAssembly (file, parameters);

            return null;
        }
Пример #6
0
        AssemblyDefinition GetAssemblyInNetGac(AssemblyNameReference reference, ReaderParameters parameters)
        {
            var gacs = new [] { "GAC_MSIL", "GAC_32", "GAC_64", "GAC" };
            var prefixes = new [] { string.Empty, "v4.0_" };

            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < gacs.Length; j++) {
                    var gac = Path.Combine (gac_paths [i], gacs [j]);
                    var file = GetAssemblyFile (reference, prefixes [i], gac);
                    if (Directory.Exists (gac) && File.Exists (file))
                        return GetAssembly (file, parameters);
                }
            }

            return null;
        }
Пример #7
0
        AssemblyDefinition GetAssemblyInMonoGac(AssemblyNameReference reference, ReaderParameters parameters)
        {
            for (int i = 0; i < gac_paths.Count; i++) {
                var gac_path = gac_paths [i];
                var file = GetAssemblyFile (reference, string.Empty, gac_path);
                if (File.Exists (file))
                    return GetAssembly (file, parameters);
            }

            return null;
        }
Пример #8
0
        AssemblyDefinition GetAssemblyInGac(AssemblyNameReference reference, ReaderParameters parameters)
        {
            if (reference.PublicKeyToken == null || reference.PublicKeyToken.Length == 0)
                return null;

            if (gac_paths == null)
                gac_paths = GetGacPaths ();

            if (on_mono)
                return GetAssemblyInMonoGac (reference, parameters);

            return GetAssemblyInNetGac (reference, parameters);
        }
Пример #9
0
        static string GetAssemblyFile(AssemblyNameReference reference, string prefix, string gac)
        {
            var gac_folder = new StringBuilder ()
                .Append (prefix)
                .Append (reference.Version)
                .Append ("__");

            for (int i = 0; i < reference.PublicKeyToken.Length; i++)
                gac_folder.Append (reference.PublicKeyToken [i].ToString ("x2"));

            return Path.Combine (
                Path.Combine (
                    Path.Combine (gac, reference.Name), gac_folder.ToString ()),
                reference.Name + ".dll");
        }
Пример #10
0
 public virtual AssemblyDefinition Resolve(AssemblyNameReference name)
 {
     return Resolve (name, new ReaderParameters ());
 }
Пример #11
0
            bool TryLookupReference(string name, out AssemblyNameReference reference)
            {
                var references = module.AssemblyReferences;

                for (int i = 0; i < references.Count; i++) {
                    reference = references [i];
                    if (reference.Name == name)
                        return true;
                }

                reference = null;
                return false;
            }
Пример #12
0
            public AssemblyNameReference GetCoreLibraryReference()
            {
                if (core_library != null)
                    return core_library;

                const string mscorlib = "mscorlib";
                const string system_runtime = "System.Runtime";

                if (TryLookupReference (mscorlib, out core_library))
                    return core_library;

                if (TryLookupReference (system_runtime, out core_library))
                    return core_library;

                core_library = new AssemblyNameReference {
                    Name = mscorlib,
                    Version = GetCorlibVersion (),
                    PublicKeyToken = new byte [] { 0xb7, 0x7a, 0x5c, 0x56, 0x19, 0x34, 0xe0, 0x89 },
                };

                module.AssemblyReferences.Add (core_library);

                return core_library;
            }
Пример #13
0
        public static AssemblyNameReference Parse(string fullName)
        {
            if (fullName == null)
                throw new ArgumentNullException ("fullName");
            if (fullName.Length == 0)
                throw new ArgumentException ("Name can not be empty");

            var name = new AssemblyNameReference ();
            var tokens = fullName.Split (',');
            for (int i = 0; i < tokens.Length; i++) {
                var token = tokens [i].Trim ();

                if (i == 0) {
                    name.Name = token;
                    continue;
                }

                var parts = token.Split ('=');
                if (parts.Length != 2)
                    throw new ArgumentException ("Malformed name");

                switch (parts [0].ToLowerInvariant ()) {
                case "version":
                    name.Version = new Version (parts [1]);
                    break;
                case "culture":
                    name.Culture = parts [1] == "neutral" ? "" : parts [1];
                    break;
                case "publickeytoken":
                    var pk_token = parts [1];
                    if (pk_token == "null")
                        break;

                    name.PublicKeyToken = new byte [pk_token.Length / 2];
                    for (int j = 0; j < name.PublicKeyToken.Length; j++)
                        name.PublicKeyToken [j] = Byte.Parse (pk_token.Substring (j * 2, 2), NumberStyles.HexNumber);

                    break;
                }
            }

            return name;
        }
Пример #14
0
 public AssemblyLinkedResource(string name, ManifestResourceAttributes flags, AssemblyNameReference reference)
     : base(name, flags)
 {
     this.reference = reference;
 }
Пример #15
0
 public AssemblyResolutionException(AssemblyNameReference reference)
     : base(string.Format ("Failed to resolve assembly: '{0}'", reference))
 {
     this.reference = reference;
 }
Пример #16
0
 public AssemblyResolveEventArgs(AssemblyNameReference reference)
 {
     this.reference = reference;
 }
Пример #17
0
        public virtual AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
        {
            if (name == null)
                throw new ArgumentNullException ("name");
            if (parameters == null)
                parameters = new ReaderParameters ();

            var assembly = SearchDirectory (name, directories, parameters);
            if (assembly != null)
                return assembly;

            if (name.IsRetargetable) {
                // if the reference is retargetable, zero it
                name = new AssemblyNameReference (name.Name, Mixin.ZeroVersion) {
                    PublicKeyToken = Empty<byte>.Array,
                };
            }

            var framework_dir = Path.GetDirectoryName (typeof (object).Module.FullyQualifiedName);

            if (IsZero (name.Version)) {
                assembly = SearchDirectory (name, new [] { framework_dir }, parameters);
                if (assembly != null)
                    return assembly;
            }

            if (name.Name == "mscorlib") {
                assembly = GetCorlib (name, parameters);
                if (assembly != null)
                    return assembly;
            }

            assembly = GetAssemblyInGac (name, parameters);
            if (assembly != null)
                return assembly;

            assembly = SearchDirectory (name, new [] { framework_dir }, parameters);
            if (assembly != null)
                return assembly;

            if (ResolveFailure != null) {
                assembly = ResolveFailure (this, name);
                if (assembly != null)
                    return assembly;
            }

            throw new AssemblyResolutionException (name);
        }