/// <summary> /// Find the highest version of the assemblyName in the redist list for framework assemblies taking into account the simplename, culture and public key. /// </summary> /// <param name="assemblyName">The name of the assembly we would like to find the highest version for</param> /// <returns>Key value pair, K: Assembly entry of highest value in the redist list. V: AssemblyNameExtension with the version information or null if the name could not be found</returns> internal AssemblyEntry FindHighestVersionInRedistList(AssemblyNameExtension assemblyName) { // The assembly we are looking for is not listed in a redist list which contains framework assemblies. We do not want to find // find non framework assembly entries. if (!FrameworkAssemblyEntryInRedist(assemblyName)) { return(null); } // Look up an assembly with the same base name in the installedAssemblyTables. // This list should be sorted alphabetically by simple name and then greatest verion foreach (AssemblyEntry tableCandidate in _redistList.FindAssemblyNameFromSimpleName(assemblyName.Name)) { // Make an AssemblyNameExtension for comparing. AssemblyNameExtension mostRecentAssemblyNameCandidate = tableCandidate.AssemblyNameExtension; // Optimize performance for the whidbey case by doing an exact comparison first. if (mostRecentAssemblyNameCandidate.EqualsIgnoreVersion(assemblyName)) { return(tableCandidate); } } return(null); }
/// <summary> /// Cached implementation of GetAssemblyName. /// </summary> /// <param name="path">The path to the file</param> /// <returns>The assembly name.</returns> private AssemblyNameExtension GetAssemblyName(string path) { // If the assembly is in an FX folder and its a well-known assembly // then we can short-circuit the File IO involved with GetAssemblyName() if (redistList != null) { string extension = Path.GetExtension(path); if (string.Equals(extension, ".dll", StringComparison.OrdinalIgnoreCase)) { IEnumerable <AssemblyEntry> assemblyNames = redistList.FindAssemblyNameFromSimpleName ( Path.GetFileNameWithoutExtension(path) ); string filename = Path.GetFileName(path); foreach (AssemblyEntry a in assemblyNames) { string pathFromRedistList = Path.Combine(a.FrameworkDirectory, filename); if (String.Equals(path, pathFromRedistList, StringComparison.OrdinalIgnoreCase)) { return(new AssemblyNameExtension(a.FullName)); } } } } // Not a well-known FX assembly so now check the cache. FileState fileState = GetFileState(path); if (fileState.Assembly == null) { fileState.Assembly = getAssemblyName(path); // Certain assemblies, like mscorlib may not have metadata. // Avoid continuously calling getAssemblyName on these files by // recording these as having an empty name. if (fileState.Assembly == null) { fileState.Assembly = AssemblyNameExtension.UnnamedAssembly; } isDirty = true; } if (fileState.Assembly.IsUnnamedAssembly) { return(null); } return(fileState.Assembly); }