/// <summary> /// If the version is not set for an assembly reference, go through the redist list and find the highest version for that assembly. /// Make sure when matching the assembly in the redist that we take into account the publicKeyToken and the Culture. /// </summary> internal static AssemblyNameExtension GetHighestVersionInRedist(InstalledAssemblies installedAssemblies, AssemblyNameExtension assemblyName) { AssemblyNameExtension assemblyNameToUse = assemblyName; if ((assemblyNameToUse.Version == null && installedAssemblies != null)) { // If there are multiple entries in the redist list for this assembly, let's // pick the one with the highest version and resolve it. foreach (AssemblyEntry a in installedAssemblies.FindAssemblyNameFromSimpleName(assemblyName.Name)) { var current = new AssemblyNameExtension(a.FullName); // If the current version is higher than the previously looked at. if (current.Version != null && current.Version.CompareTo(assemblyNameToUse.Version) > 0) { // Only compare the Culture and the public key token, the simple names will ALWAYS be the same and the version we do not care about. if (assemblyName.PartialNameCompare(current, PartialComparisonFlags.Culture | PartialComparisonFlags.PublicKeyToken)) { assemblyNameToUse = current; } } } } return(assemblyNameToUse); }
/// <summary> /// Compile search paths into an array of resolvers. /// </summary> /// <param name="buildEngine"></param> /// <param name="searchPaths"></param> /// <param name="candidateAssemblyFiles">Paths to assembly files mentioned in the project.</param> /// <param name="targetProcessorArchitecture">Like x86 or IA64\AMD64, the processor architecture being targetted.</param> /// <param name="frameworkPaths">Paths to FX folders.</param> /// <param name="fileExists"></param> /// <param name="getAssemblyName"></param> /// <param name="getRegistrySubKeyNames"></param> /// <param name="getRegistrySubKeyDefaultValue"></param> /// <param name="openBaseKey"></param> /// <param name="installedAssemblies"></param> /// <param name="getRuntimeVersion"></param> /// <param name="targetedRuntimeVersion"></param> /// <param name="getAssemblyPathInGac"></param> /// <param name="log"></param> /// <returns></returns> public static Resolver[] CompileSearchPaths ( IBuildEngine buildEngine, string[] searchPaths, string[] candidateAssemblyFiles, System.Reflection.ProcessorArchitecture targetProcessorArchitecture, string[] frameworkPaths, FileExists fileExists, GetAssemblyName getAssemblyName, #if FEATURE_WIN32_REGISTRY GetRegistrySubKeyNames getRegistrySubKeyNames, GetRegistrySubKeyDefaultValue getRegistrySubKeyDefaultValue, OpenBaseKey openBaseKey, #endif InstalledAssemblies installedAssemblies, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVersion, GetAssemblyPathInGac getAssemblyPathInGac, TaskLoggingHelper log ) { var resolvers = new Resolver[searchPaths.Length]; for (int p = 0; p < searchPaths.Length; ++p) { string basePath = searchPaths[p]; // Was {HintPathFromItem} specified? If so, take the Item's // HintPath property. if (0 == String.Compare(basePath, AssemblyResolutionConstants.hintPathSentinel, StringComparison.OrdinalIgnoreCase)) { resolvers[p] = new HintPathResolver(searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion); } else if (0 == String.Compare(basePath, AssemblyResolutionConstants.frameworkPathSentinel, StringComparison.OrdinalIgnoreCase)) { resolvers[p] = new FrameworkPathResolver(frameworkPaths, installedAssemblies, searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion); } else if (0 == String.Compare(basePath, AssemblyResolutionConstants.rawFileNameSentinel, StringComparison.OrdinalIgnoreCase)) { resolvers[p] = new RawFilenameResolver(searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion); } else if (0 == String.Compare(basePath, AssemblyResolutionConstants.candidateAssemblyFilesSentinel, StringComparison.OrdinalIgnoreCase)) { resolvers[p] = new CandidateAssemblyFilesResolver(candidateAssemblyFiles, searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion); } #if FEATURE_GAC else if (0 == String.Compare(basePath, AssemblyResolutionConstants.gacSentinel, StringComparison.OrdinalIgnoreCase)) { resolvers[p] = new GacResolver(targetProcessorArchitecture, searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion, getAssemblyPathInGac); } #endif else if (0 == String.Compare(basePath, AssemblyResolutionConstants.assemblyFoldersSentinel, StringComparison.OrdinalIgnoreCase)) { resolvers[p] = new AssemblyFoldersResolver(searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion); } #if FEATURE_WIN32_REGISTRY // Check for AssemblyFoldersEx sentinel. else if (0 == String.Compare(basePath, 0, AssemblyResolutionConstants.assemblyFoldersExSentinel, 0, AssemblyResolutionConstants.assemblyFoldersExSentinel.Length, StringComparison.OrdinalIgnoreCase)) { resolvers[p] = new AssemblyFoldersExResolver(searchPaths[p], getAssemblyName, fileExists, getRegistrySubKeyNames, getRegistrySubKeyDefaultValue, getRuntimeVersion, openBaseKey, targetedRuntimeVersion, targetProcessorArchitecture, true, buildEngine); } #endif else if (0 == String.Compare(basePath, 0, AssemblyResolutionConstants.assemblyFoldersFromConfigSentinel, 0, AssemblyResolutionConstants.assemblyFoldersFromConfigSentinel.Length, StringComparison.OrdinalIgnoreCase)) { resolvers[p] = new AssemblyFoldersFromConfigResolver(searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion, targetProcessorArchitecture, true, buildEngine, log); } else { resolvers[p] = new DirectoryResolver(searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion); } } return(resolvers); }
/// <summary> /// Construct. /// </summary> public FrameworkPathResolver(string[] frameworkPaths, InstalledAssemblies installedAssemblies, string searchPathElement, GetAssemblyName getAssemblyName, FileExists fileExists, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVesion) : base(searchPathElement, getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVesion, System.Reflection.ProcessorArchitecture.None, false) { _frameworkPaths = frameworkPaths; _installedAssemblies = installedAssemblies; }