示例#1
0
        /// <summary>
        /// Given an unresolved reference (one that we don't know the full name for yet), figure out the 
        /// full name. Should only be called on references that haven't been resolved yet--otherwise, its
        /// a perf problem.
        /// </summary>
        /// <param name="referenceFusionName">The fusion name for this reference.</param>
        /// <param name="rawFileNameCandidate">The file name to match if {RawFileName} is seen. (May be null).</param>
        /// <param name="reference">The reference object.</param>
        private void ResolveReference
        (
            AssemblyNameExtension assemblyName,
            string rawFileNameCandidate,
            Reference reference
        )
        {
            // Now, resolve this reference.
            string resolvedPath = null;
            string resolvedSearchPath = String.Empty;
            bool userRequestedSpecificFile = false;

            // A list of assemblies that might have been matches but weren't
            ArrayList assembliesConsideredAndRejected = new ArrayList();

            // First, look for the dependency in the parents' directories. Unless they are resolved from the GAC or assemblyFoldersEx then 
            // we should make sure we use the GAC and assemblyFolders resolvers themserves rather than a directory resolver to find the reference.\
            // this way we dont get assemblies pulled from the GAC or AssemblyFolders but dont have the marking that they were pulled form there.
            Hashtable parentReferenceFolderHash = new Hashtable(StringComparer.OrdinalIgnoreCase);
            List<string> parentReferenceFolders = new List<string>();
            foreach (Reference parentReference in reference.GetDependees())
            {
                CalcuateParentAssemblyDirectories(parentReferenceFolderHash, parentReferenceFolders, parentReference);
            }

            // Build the set of resolvers.
            List<Resolver[]> jaggedResolvers = new List<Resolver[]>();

            // If a reference has an SDK name on it then we must ONLY resolve it from the SDK which matches the SDKName on the refernce metadata
            // this is to support the case where a single reference assembly is selected from the SDK.
            // If a reference has the SDKName metadata on it then we will only search using a single resolver, that is the InstalledSDKResolver.
            if (reference.SDKName.Length > 0)
            {
                jaggedResolvers.Add(new Resolver[] { new InstalledSDKResolver(_resolvedSDKReferences, "SDKResolver", _getAssemblyName, _fileExists, _getRuntimeVersion, _targetedRuntimeVersion) });
            }
            else
            {
                jaggedResolvers.Add(AssemblyResolution.CompileDirectories(parentReferenceFolders, _fileExists, _getAssemblyName, _getRuntimeVersion, _targetedRuntimeVersion));
                jaggedResolvers.Add(_compiledSearchPaths);
            }

            // Resolve
            try
            {
                resolvedPath = AssemblyResolution.ResolveReference
                (
                    jaggedResolvers,
                    assemblyName,
                    reference.SDKName,
                    rawFileNameCandidate,
                    reference.IsPrimary,
                    reference.WantSpecificVersion,
                    reference.GetExecutableExtensions(_allowedAssemblyExtensions),
                    reference.HintPath,
                    reference.AssemblyFolderKey,
                    assembliesConsideredAndRejected,
                    out resolvedSearchPath,
                    out userRequestedSpecificFile
                );
            }
            catch (System.BadImageFormatException e)
            {
                reference.AddError(new DependencyResolutionException(e.Message, e));
            }

            // Update the list of assemblies considered and rejected.
            reference.AddAssembliesConsideredAndRejected(assembliesConsideredAndRejected);

            // If the path was resolved, then specify the full path on the reference.
            if (resolvedPath != null)
            {
                if (!Path.IsPathRooted(resolvedPath))
                {
                    resolvedPath = Path.GetFullPath(resolvedPath);
                }

                reference.FullPath = resolvedPath;
                reference.ResolvedSearchPath = resolvedSearchPath;
                reference.UserRequestedSpecificFile = userRequestedSpecificFile;
            }
            else
            {
                if (assemblyName != null)
                {
                    reference.AddError
                    (
                        new ReferenceResolutionException
                        (
                            ResourceUtilities.FormatResourceString("General.CouldNotLocateAssembly", assemblyName.FullName),
                            null
                        )
                    );
                }
            }
        }
 private void ResolveReference(AssemblyNameExtension assemblyName, string rawFileNameCandidate, Reference reference)
 {
     string path = null;
     string resolvedSearchPath = string.Empty;
     bool userRequestedSpecificFile = false;
     ArrayList assembliesConsideredAndRejected = new ArrayList();
     Hashtable parentReferenceFolderHash = new Hashtable(StringComparer.OrdinalIgnoreCase);
     List<string> parentReferenceFolders = new List<string>();
     foreach (Reference reference2 in reference.GetDependees())
     {
         CalcuateParentAssemblyDirectories(parentReferenceFolderHash, parentReferenceFolders, reference2);
     }
     List<Microsoft.Build.Tasks.Resolver[]> jaggedResolvers = new List<Microsoft.Build.Tasks.Resolver[]> {
         AssemblyResolution.CompileDirectories(parentReferenceFolders, this.fileExists, this.getAssemblyName, this.getRuntimeVersion, this.targetedRuntimeVersion),
         this.compiledSearchPaths
     };
     try
     {
         path = AssemblyResolution.ResolveReference(jaggedResolvers, assemblyName, rawFileNameCandidate, reference.IsPrimary, reference.WantSpecificVersion, reference.GetExecutableExtensions(this.allowedAssemblyExtensions), reference.HintPath, reference.AssemblyFolderKey, assembliesConsideredAndRejected, out resolvedSearchPath, out userRequestedSpecificFile);
     }
     catch (BadImageFormatException exception)
     {
         reference.AddError(new DependencyResolutionException(exception.Message, exception));
     }
     reference.AddAssembliesConsideredAndRejected(assembliesConsideredAndRejected);
     if (path != null)
     {
         if (!Path.IsPathRooted(path))
         {
             path = Path.GetFullPath(path);
         }
         reference.FullPath = path;
         reference.ResolvedSearchPath = resolvedSearchPath;
         reference.UserRequestedSpecificFile = userRequestedSpecificFile;
     }
     else if (assemblyName != null)
     {
         reference.AddError(new ReferenceResolutionException(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("General.CouldNotLocateAssembly", new object[] { assemblyName.FullName }), null));
     }
 }