private AssemblyEntry GetUnifiedAssemblyEntry(string assemblyName) { if (assemblyName == null) { throw new ArgumentNullException("assemblyName"); } if (!string.Equals(this.cachedKey, assemblyName, StringComparison.OrdinalIgnoreCase)) { this.cachedKey = string.Empty; this.cachedValue = null; string simpleName = GetSimpleName(assemblyName); if (this.simpleNameMap.ContainsKey(simpleName)) { int num = (int)this.simpleNameMap[simpleName]; AssemblyNameExtension extension = new AssemblyNameExtension(this.assemblyList[num].FullName); for (int i = num; i < this.assemblyList.Count; i++) { AssemblyEntry entry = this.assemblyList[i]; if (!string.Equals(simpleName, entry.SimpleName, StringComparison.OrdinalIgnoreCase)) { break; } AssemblyNameExtension extension2 = new AssemblyNameExtension(assemblyName); AssemblyNameExtension assemblyNameExtension = entry.AssemblyNameExtension; if (extension2.EqualsIgnoreVersion(assemblyNameExtension) && (extension.Version <= assemblyNameExtension.Version)) { this.cachedKey = assemblyName; this.cachedValue = entry; break; } } } } return(this.cachedValue); }
public bool FrameworkAssemblyEntryInRedist(AssemblyNameExtension assemblyName) { Microsoft.Build.Shared.ErrorUtilities.VerifyThrowArgumentNull(assemblyName, "assemblyName"); NGen <bool> gen = 0; if (!this.assemblyNameInRedist.TryGetValue(assemblyName, out gen)) { string simpleName = GetSimpleName(assemblyName.Name); if (this.simpleNameMap.ContainsKey(simpleName)) { int num = (int)this.simpleNameMap[simpleName]; for (int i = num; i < this.assemblyList.Count; i++) { AssemblyEntry entry = this.assemblyList[i]; if (!string.Equals(simpleName, entry.SimpleName, StringComparison.OrdinalIgnoreCase)) { break; } if (entry.RedistName.StartsWith("Microsoft-Windows-CLRCoreComp", StringComparison.OrdinalIgnoreCase)) { AssemblyNameExtension extension = assemblyName; AssemblyNameExtension assemblyNameExtension = entry.AssemblyNameExtension; if (extension.PartialNameCompare(assemblyNameExtension, PartialComparisonFlags.PublicKeyToken | PartialComparisonFlags.Culture | PartialComparisonFlags.SimpleName)) { gen = 1; break; } } } } this.assemblyNameInRedist.Add(assemblyName, gen); } return((bool)gen); }
internal string RedistName(string assemblyName) { AssemblyEntry unifiedAssemblyEntry = this.GetUnifiedAssemblyEntry(assemblyName); if (unifiedAssemblyEntry != null) { return(unifiedAssemblyEntry.RedistName); } return(null); }
internal bool?IsRedistRoot(string assemblyName) { AssemblyEntry unifiedAssemblyEntry = this.GetUnifiedAssemblyEntry(assemblyName); if (unifiedAssemblyEntry != null) { return(unifiedAssemblyEntry.IsRedistRoot); } return(null); }
public string GetUnifiedAssemblyName(string assemblyName) { AssemblyEntry unifiedAssemblyEntry = this.GetUnifiedAssemblyEntry(assemblyName); if (unifiedAssemblyEntry != null) { return(unifiedAssemblyEntry.FullName); } return(assemblyName); }
private void BuildMap() { this.assemblyList.Sort(sortByVersionDescending); for (int i = 0; i < this.assemblyList.Count; i++) { AssemblyEntry entry = this.assemblyList[i]; if (!this.simpleNameMap.ContainsKey(entry.SimpleName)) { this.simpleNameMap.Add(entry.SimpleName, i); } } }
/// <summary> /// Unify an assembly name according to the fx retarget rules. /// </summary> /// <param name="assemblyName">The unify-from assembly name.</param> /// <param name="unifiedVersion">The new version number.</param> /// <param name="isPrerequisite">Whether this assembly will be available on target machines.</param> /// <param name="isRedistRoot">May be true, false or null. Null means there was no IsRedistRoot in the redist list.</param> /// <param name="redistName">Name of the corresponding Resist specified in the redist list.</param> internal void GetInfo ( AssemblyNameExtension assemblyName, out Version unifiedVersion, out bool isPrerequisite, out bool?isRedistRoot, out string redistName ) { unifiedVersion = assemblyName.Version; isPrerequisite = false; isRedistRoot = null; redistName = null; // Short-circuit in cases where there is no redist list. if (_redistList == null) { return; } // If there's no version, for example in a simple name, then no remapping is possible, // and this is not a prerequisite. if (assemblyName.Version == null) { return; } AssemblyEntry highestVersionFromRedistList = FindHighestVersionInRedistList(assemblyName); // Could not find the assembly in the redist list. Return as there has been no redist list unification if (highestVersionFromRedistList == null) { return; } // Dont allow downgrading of reference version due to redist unification because this is automatic rather than something like an appconfig which // has to be manually set. However if the major version is 255 then we do want to unify down the version number. if (assemblyName.Version <= highestVersionFromRedistList.AssemblyNameExtension.Version || assemblyName.Version.Major == 255) { unifiedVersion = highestVersionFromRedistList.AssemblyNameExtension.Version; isPrerequisite = _redistList.IsPrerequisiteAssembly(highestVersionFromRedistList.FullName); isRedistRoot = _redistList.IsRedistRoot(highestVersionFromRedistList.FullName); redistName = _redistList.RedistName(highestVersionFromRedistList.FullName); return; } }
internal void GetInfo(AssemblyNameExtension assemblyName, out Version unifiedVersion, out bool isPrerequisite, out bool?isRedistRoot, out string redistName) { unifiedVersion = assemblyName.Version; isPrerequisite = false; isRedistRoot = 0; redistName = null; if ((this.redistList != null) && (assemblyName.Version != null)) { AssemblyEntry entry = this.FindHighestVersionInRedistList(assemblyName); if ((entry != null) && (assemblyName.Version <= entry.AssemblyNameExtension.Version)) { unifiedVersion = entry.AssemblyNameExtension.Version; isPrerequisite = this.redistList.IsPrerequisiteAssembly(entry.FullName); isRedistRoot = this.redistList.IsRedistRoot(entry.FullName); redistName = this.redistList.RedistName(entry.FullName); } } }
internal AssemblyEntry[] FindAssemblyNameFromSimpleName(string simpleName) { List <AssemblyEntry> list = new List <AssemblyEntry>(); if (this.simpleNameMap.ContainsKey(simpleName)) { int num = (int)this.simpleNameMap[simpleName]; for (int i = num; i < this.assemblyList.Count; i++) { AssemblyEntry item = this.assemblyList[i]; if (!string.Equals(simpleName, item.SimpleName, StringComparison.OrdinalIgnoreCase)) { break; } list.Add(item); this.cachedKey = item.FullName; this.cachedValue = item; } } return(list.ToArray()); }
internal static string ReadFile(AssemblyTableInfo assemblyTableInfo, List <AssemblyEntry> assembliesList, ArrayList errorsList, ArrayList errorFilenamesList) { string path = assemblyTableInfo.Path; string redistName = null; XmlTextReader reader = null; Dictionary <string, AssemblyEntry> dictionary = new Dictionary <string, AssemblyEntry>(StringComparer.OrdinalIgnoreCase); try { reader = new XmlTextReader(path); bool flag = false; while (reader.Read()) { if ((reader.NodeType != XmlNodeType.Element) || !string.Equals(reader.Name, "FileList", StringComparison.OrdinalIgnoreCase)) { continue; } flag = true; reader.MoveToFirstAttribute(); do { if (string.Equals(reader.Name, "Redist", StringComparison.OrdinalIgnoreCase)) { redistName = reader.Value; break; } }while (reader.MoveToNextAttribute()); reader.MoveToElement(); break; } if (flag) { flag = false; while (reader.Read()) { if ((reader.NodeType == XmlNodeType.Element) && string.Equals(reader.Name, "File", StringComparison.OrdinalIgnoreCase)) { string str3; string str4; string str5; string str6; string str7; string str8; bool flag2; bool flag3; flag = true; Dictionary <string, string> dictionary2 = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); reader.MoveToFirstAttribute(); do { dictionary2.Add(reader.Name, reader.Value); }while (reader.MoveToNextAttribute()); dictionary2.TryGetValue("AssemblyName", out str3); dictionary2.TryGetValue("Version", out str4); dictionary2.TryGetValue("PublicKeyToken", out str5); dictionary2.TryGetValue("Culture", out str6); dictionary2.TryGetValue("InGAC", out str7); dictionary2.TryGetValue("IsRedistRoot", out str8); if (!bool.TryParse(str7, out flag2)) { flag2 = true; } bool?isRedistRoot = null; if (bool.TryParse(str8, out flag3)) { isRedistRoot = new bool?(flag3); } if (((!string.IsNullOrEmpty(str3) && !string.IsNullOrEmpty(str4)) && !string.IsNullOrEmpty(str5)) && !string.IsNullOrEmpty(str6)) { AssemblyEntry entry = new AssemblyEntry(str3, str4, str5, str6, flag2, isRedistRoot, redistName, assemblyTableInfo.FrameworkDirectory); string key = string.Format(CultureInfo.InvariantCulture, "{0},{1}", new object[] { entry.FullName, !entry.IsRedistRoot.HasValue ? "null" : entry.IsRedistRoot.ToString() }); AssemblyEntry entry2 = null; dictionary.TryGetValue(key, out entry2); if ((entry2 == null) || ((entry2 != null) && entry.InGAC)) { dictionary[key] = entry; } } reader.MoveToElement(); } } } } catch (XmlException exception) { errorsList.Add(exception); errorFilenamesList.Add(path); } catch (Exception exception2) { if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception2)) { throw; } errorsList.Add(exception2); errorFilenamesList.Add(path); } finally { if (reader != null) { reader.Close(); } } foreach (AssemblyEntry entry3 in dictionary.Values) { assembliesList.Add(entry3); } return(redistName); }
public bool IsPrerequisiteAssembly(string assemblyName) { AssemblyEntry unifiedAssemblyEntry = this.GetUnifiedAssemblyEntry(assemblyName); return((unifiedAssemblyEntry != null) && unifiedAssemblyEntry.InGAC); }
public bool IsFrameworkAssembly(string assemblyName) { AssemblyEntry unifiedAssemblyEntry = this.GetUnifiedAssemblyEntry(assemblyName); return(((unifiedAssemblyEntry != null) && !string.IsNullOrEmpty(unifiedAssemblyEntry.RedistName)) && unifiedAssemblyEntry.RedistName.StartsWith("Microsoft-Windows-CLRCoreComp", StringComparison.OrdinalIgnoreCase)); }
public void ReverseAssemblyNameExtensionComparer() { IComparer sortByVersionDescending = new RedistList.SortByVersionDescending(); AssemblyEntry a1 = new AssemblyEntry("Microsoft.Build.Engine", "1.0.0.0", "b03f5f7f11d50a3a", "neutral", true, true, "Foo", "none", true); AssemblyEntry a2 = new AssemblyEntry("Microsoft.Build.Engine", "2.0.0.0", "b03f5f7f11d50a3a", "neutral", true, true, "Foo", "none", false); AssemblyEntry a3 = new AssemblyEntry("Microsoft.Build.Engine", "3.0.0.0", "b03f5f7f11d50a3a", "neutral", true, true, "Foo", "none", true); AssemblyEntry a4 = new AssemblyEntry("A", "3.0.0.0", "b03f5f7f11d50a3a", "neutral", true, true, "Foo", "none", true); AssemblyEntry a5 = new AssemblyEntry("B", "3.0.0.0", "b03f5f7f11d50a3a", "neutral", true, true, "Foo", "none", true); // Verify versions sort correctly when simple name is same Assert.Equal(0, sortByVersionDescending.Compare(a1, a1)); Assert.Equal(1, sortByVersionDescending.Compare(a1, a2)); Assert.Equal(1, sortByVersionDescending.Compare(a1, a3)); Assert.Equal(-1, sortByVersionDescending.Compare(a2, a1)); Assert.Equal(1, sortByVersionDescending.Compare(a2, a3)); // Verify the names sort alphabetically Assert.Equal(-1, sortByVersionDescending.Compare(a4, a5)); }