public override PortableExecutableReference ResolveMissingAssembly(MetadataReference definition, AssemblyIdentity referenceIdentity)
        {
            // look in the GAC:
            if (GacFileResolver != null && referenceIdentity.IsStrongName)
            {
                var path = GacFileResolver.Resolve(referenceIdentity.GetDisplayName());
                if (path != null)
                {
                    return(CreateResolvedMissingReference(path));
                }
            }

            // look in the directory of the requesting definition:
            var definitionPath = (definition as PortableExecutableReference)?.FilePath;

            if (definitionPath != null)
            {
                var pathWithoutExtension = PathUtilities.CombinePathsUnchecked(PathUtilities.GetDirectoryName(definitionPath), referenceIdentity.Name);
                foreach (var extension in AssemblyExtensions)
                {
                    var fullPath = pathWithoutExtension + extension;
                    if (File.Exists(fullPath))
                    {
                        return(CreateResolvedMissingReference(fullPath));
                    }
                }
            }

            return(null);
        }
        public override ImmutableArray <PortableExecutableReference> ResolveReference(string reference, string baseFilePath, MetadataReferenceProperties properties)
        {
            if (PathResolver != null && PathUtilities.IsFilePath(reference))
            {
                var resolvedPath = PathResolver.ResolvePath(reference, baseFilePath);
                if (resolvedPath == null)
                {
                    return(ImmutableArray <PortableExecutableReference> .Empty);
                }

                return(ImmutableArray.Create(_fileReferenceProvider(resolvedPath, properties)));
            }

            if (PackageResolver != null)
            {
                var paths = PackageResolver.ResolveNuGetPackage(reference);
                if (!paths.IsDefaultOrEmpty)
                {
                    return(paths.SelectAsArray(path => _fileReferenceProvider(path, properties)));
                }
            }

            if (GacFileResolver != null)
            {
                var path = GacFileResolver.Resolve(reference);
                if (path != null)
                {
                    return(ImmutableArray.Create(_fileReferenceProvider(path, properties)));
                }
            }

            return(ImmutableArray <PortableExecutableReference> .Empty);
        }
        public override ImmutableArray <PortableExecutableReference> ResolveReference(string reference, string baseFilePath, MetadataReferenceProperties properties)
        {
            string packageName;
            string packageVersion;

            if (NuGetPackageResolver.TryParsePackageReference(reference, out packageName, out packageVersion))
            {
                if (PackageResolver != null)
                {
                    var paths = PackageResolver.ResolveNuGetPackage(packageName, packageVersion);
                    Debug.Assert(!paths.IsDefault);
                    return(paths.SelectAsArray(path => _fileReferenceProvider(path, properties)));
                }
            }
            else if (PathUtilities.IsFilePath(reference))
            {
                if (PathResolver != null)
                {
                    var resolvedPath = PathResolver.ResolvePath(reference, baseFilePath);
                    if (resolvedPath != null)
                    {
                        return(ImmutableArray.Create(_fileReferenceProvider(resolvedPath, properties)));
                    }
                }
            }
            else if (GacFileResolver != null)
            {
                var path = GacFileResolver.Resolve(reference);
                if (path != null)
                {
                    return(ImmutableArray.Create(_fileReferenceProvider(path, properties)));
                }
            }
            return(ImmutableArray <PortableExecutableReference> .Empty);
        }
Ejemplo n.º 4
0
        public override PortableExecutableReference ResolveMissingAssembly(MetadataReference definition, AssemblyIdentity referenceIdentity)
        {
            // look in the GAC:
            if (GacFileResolver != null && referenceIdentity.IsStrongName)
            {
                var path = GacFileResolver.Resolve(referenceIdentity.GetDisplayName());
                if (path != null)
                {
                    return(CreateResolvedMissingReference(path));
                }
            }

            // look into a directory containing CorLib:
            if (_useCoreResolver)
            {
                var result = ResolveTrustedPlatformAssemblyCore(referenceIdentity.Name, s_resolvedMissingAssemblyReferenceProperties);
                if (result != null)
                {
                    return(result);
                }
            }

            // look in the directory of the requesting definition:
            string definitionPath = (definition as PortableExecutableReference)?.FilePath;

            if (definitionPath != null)
            {
                string pathWithoutExtension = PathUtilities.CombinePathsUnchecked(PathUtilities.GetDirectoryName(definitionPath), referenceIdentity.Name);
                foreach (string extension in AssemblyExtensions)
                {
                    string fullPath = pathWithoutExtension + extension;
                    if (File.Exists(fullPath))
                    {
                        return(CreateResolvedMissingReference(fullPath));
                    }
                }
            }

            return(null);
        }