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.IO;
6 using System.Reflection;
7 using System.Collections;
8 using Microsoft.Build.Shared;
9 
10 namespace Microsoft.Build.Tasks
11 {
12     /// <summary>
13     /// Resolve searchpath type {RawFileName}
14     /// </summary>
15     internal class RawFilenameResolver : Resolver
16     {
17         /// <summary>
18         /// Construct.
19         /// </summary>
20         /// <param name="searchPathElement"></param>
21         /// <param name="getAssemblyName"></param>
22         /// <param name="fileExists"></param>
RawFilenameResolver(string searchPathElement, GetAssemblyName getAssemblyName, FileExists fileExists, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVesion)23         public RawFilenameResolver(string searchPathElement, GetAssemblyName getAssemblyName, FileExists fileExists, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVesion)
24             : base(searchPathElement, getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVesion, ProcessorArchitecture.None, false)
25         {
26         }
27 
28 
29         /// <summary>
30         /// Resolve a reference to a specific file name.
31         /// </summary>
32         /// <param name="assemblyName">The assemblyname of the reference.</param>
33         /// <param name="rawFileNameCandidate">The reference's 'include' treated as a raw file name.</param>
34         /// <param name="isPrimaryProjectReference">Whether or not this reference was directly from the project file (and therefore not a dependency)</param>
35         /// <param name="wantSpecificVersion">Whether an exact version match is requested.</param>
36         /// <param name="executableExtensions">Allowed executable extensions.</param>
37         /// <param name="hintPath">The item's hintpath value.</param>
38         /// <param name="assemblyFolderKey">Like "hklm\Vendor RegKey" as provided to a reference by the &lt;AssemblyFolderKey&gt; on the reference in the project.</param>
39         /// <param name="assembliesConsideredAndRejected">Receives the list of locations that this function tried to find the assembly. May be "null".</param>
40         /// <param name="foundPath">The path where the file was found.</param>
41         /// <param name="userRequestedSpecificFile">Whether or not the user wanted a specific file (for example, HintPath is a request for a specific file)</param>
42         /// <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 )43         public override bool Resolve
44         (
45             AssemblyNameExtension assemblyName,
46             string sdkName,
47             string rawFileNameCandidate,
48             bool isPrimaryProjectReference,
49             bool wantSpecificVersion,
50             string[] executableExtensions,
51             string hintPath,
52             string assemblyFolderKey,
53             ArrayList assembliesConsideredAndRejected,
54 
55             out string foundPath,
56             out bool userRequestedSpecificFile
57         )
58         {
59             foundPath = null;
60             userRequestedSpecificFile = false;
61 
62             if (rawFileNameCandidate != null)
63             {
64                 // {RawFileName} was passed in.
65                 if (fileExists(rawFileNameCandidate))
66                 {
67                     userRequestedSpecificFile = true;
68                     foundPath = rawFileNameCandidate;
69                     return true;
70                 }
71                 else
72                 {
73                     if (assembliesConsideredAndRejected != null)
74                     {
75                         ResolutionSearchLocation considered = null;
76                         considered = new ResolutionSearchLocation();
77                         considered.FileNameAttempted = rawFileNameCandidate;
78                         considered.SearchPath = searchPathElement;
79                         considered.Reason = NoMatchReason.NotAFileNameOnDisk;
80                         assembliesConsideredAndRejected.Add(considered);
81                     }
82                 }
83             }
84 
85 
86             return false;
87         }
88     }
89 }
90