1 // Copyright (c) Microsoft. All rights reserved. 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 4 using System; 5 using System.Reflection; 6 using System.Collections; 7 using Microsoft.Build.Shared; 8 9 namespace Microsoft.Build.Tasks 10 { 11 /// <summary> 12 /// Resolve when the searchpath type is a simple directory name. 13 /// </summary> 14 internal class DirectoryResolver : Resolver 15 { 16 /// <summary> 17 /// Construct. 18 /// </summary> 19 /// <param name="searchPathElement"></param> 20 /// <param name="getAssemblyName"></param> 21 /// <param name="fileExists"></param> DirectoryResolver(string searchPathElement, GetAssemblyName getAssemblyName, FileExists fileExists, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVesion)22 public DirectoryResolver(string searchPathElement, GetAssemblyName getAssemblyName, FileExists fileExists, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVesion) 23 : base(searchPathElement, getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVesion, System.Reflection.ProcessorArchitecture.None, false) 24 { 25 } 26 27 28 /// <summary> 29 /// Resolve a reference to a specific file name. 30 /// </summary> 31 /// <param name="assemblyName">The assemblyname of the reference.</param> 32 /// <param name="rawFileNameCandidate">The reference's 'include' treated as a raw file name.</param> 33 /// <param name="isPrimaryProjectReference">Whether or not this reference was directly from the project file (and therefore not a dependency)</param> 34 /// <param name="wantSpecificVersion">Whether an exact version match is requested.</param> 35 /// <param name="executableExtensions">Allowed executable extensions.</param> 36 /// <param name="hintPath">The item's hintpath value.</param> 37 /// <param name="assemblyFolderKey">Like "hklm\Vendor RegKey" as provided to a reference by the <AssemblyFolderKey> on the reference in the project.</param> 38 /// <param name="assembliesConsideredAndRejected">Receives the list of locations that this function tried to find the assembly. May be "null".</param> 39 /// <param name="foundPath">The path where the file was found.</param> 40 /// <param name="userRequestedSpecificFile">Whether or not the user wanted a specific file (for example, HintPath is a request for a specific file)</param> 41 /// <returns>True if the file was resolved.</returns> Resolve( AssemblyNameExtension assemblyName, string sdkName, string rawFileNameCandidate, bool isPrimaryProjectReference, bool wantSpecificVersion, string[] executableExtensions, string hintPath, string assemblyFolderKey, ArrayList assembliesConsideredAndRejected, out string foundPath, out bool userRequestedSpecificFile )42 public override bool Resolve 43 ( 44 AssemblyNameExtension assemblyName, 45 string sdkName, 46 string rawFileNameCandidate, 47 bool isPrimaryProjectReference, 48 bool wantSpecificVersion, 49 string[] executableExtensions, 50 string hintPath, 51 string assemblyFolderKey, 52 ArrayList assembliesConsideredAndRejected, 53 54 out string foundPath, 55 out bool userRequestedSpecificFile 56 ) 57 { 58 foundPath = null; 59 userRequestedSpecificFile = false; 60 61 // Resolve to the given path. 62 string resolvedPath = ResolveFromDirectory(assemblyName, isPrimaryProjectReference, wantSpecificVersion, executableExtensions, searchPathElement, assembliesConsideredAndRejected); 63 if (resolvedPath != null) 64 { 65 foundPath = resolvedPath; 66 return true; 67 } 68 69 70 return false; 71 } 72 } 73 } 74