예제 #1
0
        /// <inheritdoc />
        protected override AssemblyDefinition ResolveImpl(AssemblyDescriptor assembly)
        {
            string path = null;

            if (assembly.GetPublicKeyToken() != null)
            {
                path = ProbeGlobalAssemblyCache(assembly);
            }
            if (string.IsNullOrEmpty(path))
            {
                path = ProbeSearchDirectories(assembly);
            }

            AssemblyDefinition assemblyDef = null;

            try
            {
                assemblyDef = LoadAssemblyFromFile(path);
            }
            catch
            {
                // ignore any errors.
            }

            return(assemblyDef);
        }
예제 #2
0
        /// <inheritdoc />
        protected override AssemblyDefinition ResolveImpl(AssemblyDescriptor assembly)
        {
            string path = null;

            var token = assembly.GetPublicKeyToken();

            if (token != null && !string.IsNullOrEmpty(_installationDirectory))
            {
                path = ProbeDirectory(assembly, _installationDirectory);
            }
            if (string.IsNullOrEmpty(path))
            {
                path = ProbeSearchDirectories(assembly);
            }

            AssemblyDefinition assemblyDef = null;

            try
            {
                assemblyDef = LoadAssemblyFromFile(path);
            }
            catch
            {
                // ignore any errors.
            }

            return(assemblyDef);
        }
예제 #3
0
 /// <summary>
 /// Creates a new assembly reference, and copies over all properties of another assembly descriptor.
 /// </summary>
 /// <param name="descriptor">The assembly to base the reference on.</param>
 public AssemblyReference(AssemblyDescriptor descriptor)
     : this(new MetadataToken(TableIndex.AssemblyRef, 0))
 {
     Name             = descriptor.Name;
     Version          = descriptor.Version;
     Attributes       = descriptor.Attributes;
     HasPublicKey     = false;
     PublicKeyOrToken = descriptor.GetPublicKeyToken();
     Culture          = descriptor.Culture;
 }
예제 #4
0
        /// <summary>
        /// Probes the global assembly cache for an assembly.
        /// </summary>
        /// <param name="assembly">The assembly to lookup.</param>
        /// <returns>The path to the assembly, or <c>null</c> if none was found.</returns>
        public string Probe(AssemblyDescriptor assembly)
        {
            string fullPath = Path.Combine(_basePath, assembly.Name);

            if (Directory.Exists(fullPath))
            {
                string pubKeyTokenString = string.Join(string.Empty,
                                                       assembly.GetPublicKeyToken().Select(x => x.ToString("x2")));
                string directoryName = $"{assembly.Version}__{pubKeyTokenString}";
                if (IsPrefixed)
                {
                    directoryName = _prefix + directoryName;
                }

                string filePath = Path.Combine(fullPath, directoryName, assembly.Name);
                filePath = AssemblyResolverBase.ProbeFileFromFilePathWithoutExtension(filePath);
                if (!string.IsNullOrEmpty(filePath))
                {
                    return(filePath);
                }
            }

            return(null);
        }