internal static ReferenceAssemblyType GetPathToReferenceAssembly(Assembly a, out string path, ICollection <BuildErrorEventArgs> errors, ICollection <BuildWarningEventArgs> warnings, bool checkDependencies) { lock (s_lock) { if (AssemblyLocations.TryGetValue(a, out path)) { return(ReferenceAssemblyTypes[a]); } } if ((TargetFrameworkReferenceAssemblyPaths == null) || (TargetFrameworkReferenceAssemblyPaths.Count == 0)) { path = Util.GetAssemblyCodeBase(a); return(ReferenceAssemblyType.FrameworkAssembly); } AssemblyResolutionResult result = null; ReferenceAssemblyType nonFrameworkAssembly = ReferenceAssemblyType.NonFrameworkAssembly; if (BuildResultCompiledAssemblyBase.AssemblyIsInCodegenDir(a)) { path = Util.GetAssemblyCodeBase(a); } else { nonFrameworkAssembly = GetPathToReferenceAssembly(a, out path, errors, warnings, checkDependencies, true, out result); } StoreResults(a, path, result, nonFrameworkAssembly); return(nonFrameworkAssembly); }
/// <summary> /// Check whether an assembly has dependencies to a framework assembly of a higher version, /// report the issue as a warning or error. /// </summary> private static void CheckOutOfRangeDependencies(string assemblyName) { string dependencies = null; Assembly assembly = Assembly.Load(assemblyName); AssemblyName aName = new AssemblyName(assemblyName); // If the loaded assembly has a different version than the specified assembly, // then it is likely that there was unification or binding redirect in place. // If that is the case, then GetReferenceAssemblies won't be accurate for // finding the references of the actual assembly, so we skip checking its references. if (assembly.GetName().Version != aName.Version) { return; } foreach (AssemblyName name in assembly.GetReferencedAssemblies()) { try { Assembly referenceAssembly = CompilationSection.LoadAndRecordAssembly(name); string path; ReferenceAssemblyType referenceAssemblyType = GetPathToReferenceAssembly(referenceAssembly, out path, null, null, false /*checkDependencies*/); // We need to check the following 2 conditions: // 1. If the assembly is available in the target framework, we also need to // verify that the version being referenced is no higher than what we have // in the target framework. // 2. If the assembly is only available in a higher version framework. Version resolvedAssemblyVersion = GetAssemblyVersion(path); if (resolvedAssemblyVersion == null) { continue; } if ((referenceAssemblyType == ReferenceAssemblyType.FrameworkAssembly && resolvedAssemblyVersion < name.Version) || referenceAssemblyType == ReferenceAssemblyType.FrameworkAssemblyOnlyPresentInHigherVersion) { if (dependencies == null) { dependencies = name.FullName; } else { dependencies += "; " + name.FullName; } } } catch { // Ignore dependencies that are not found, as we are primarily concerned // with framework assemblies that are on the machine. } } if (dependencies != null) { string message = SR.GetString(SR.Higher_dependencies, assemblyName, dependencies); ReportWarningOrError(message); } }
private static bool IsFrameworkType(Type type) { // We need to make sure a type is a framework type, before we try to use s_cbmTdpBridge on it. // Also, isFrameworkType should only be called in this specific scenario, when we are trying // to use s_cbmTdpBridge. Debug.Assert(s_cbmTdpBridge != null, "s_cbmTdpBridge should not be null in IsFrameworkType"); bool result; if (!s_isFrameworkType.TryGetValue(type, out result)) { Assembly a = type.Assembly; string path; ReferenceAssemblyType referenceAssemblyType = AssemblyResolver.GetPathToReferenceAssembly(a, out path); result = (referenceAssemblyType != ReferenceAssemblyType.NonFrameworkAssembly); s_isFrameworkType.TryAdd(type, result); } return(result); }
private static void CheckOutOfRangeDependencies(string assemblyName) { string fullName = null; Assembly assembly = Assembly.Load(assemblyName); AssemblyName name = new AssemblyName(assemblyName); if (assembly.GetName().Version == name.Version) { foreach (AssemblyName name2 in assembly.GetReferencedAssemblies()) { try { string str2; ReferenceAssemblyType type = GetPathToReferenceAssembly(CompilationSection.LoadAndRecordAssembly(name2), out str2, null, null, false); Version assemblyVersion = GetAssemblyVersion(str2); if ((assemblyVersion != null) && (((type == ReferenceAssemblyType.FrameworkAssembly) && (assemblyVersion < name2.Version)) || (type == ReferenceAssemblyType.FrameworkAssemblyOnlyPresentInHigherVersion))) { if (fullName == null) { fullName = name2.FullName; } else { fullName = fullName + "; " + name2.FullName; } } } catch { } } if (fullName != null) { ReportWarningOrError(System.Web.SR.GetString("Higher_dependencies", new object[] { assemblyName, fullName })); } } }
internal static ReferenceAssemblyType GetPathToReferenceAssembly(Assembly a, out string path, ICollection <BuildErrorEventArgs> errors, ICollection <BuildWarningEventArgs> warnings, bool checkDependencies) { lock (s_lock) { if (AssemblyLocations.TryGetValue(a, out path)) { return(ReferenceAssemblyTypes[a]); } } // If there are no reference assemblies available, just use the path to the loaded assembly. if (TargetFrameworkReferenceAssemblyPaths == null || TargetFrameworkReferenceAssemblyPaths.Count == 0) { path = System.Web.UI.Util.GetAssemblyCodeBase(a); return(ReferenceAssemblyType.FrameworkAssembly); } AssemblyResolutionResult result = null; ReferenceAssemblyType referenceAssemblyType = ReferenceAssemblyType.NonFrameworkAssembly; // If the assembly is generated by us, it is a non framework assembly and does not need to be resolved. if (BuildResultCompiledAssemblyBase.AssemblyIsInCodegenDir(a)) { path = System.Web.UI.Util.GetAssemblyCodeBase(a); } else { // Try using the assembly full name. referenceAssemblyType = GetPathToReferenceAssembly(a, out path, errors, warnings, checkDependencies, true /*useFullName*/, out result); } StoreResults(a, path, result, referenceAssemblyType); return(referenceAssemblyType); }
private static void StoreResults(Assembly a, string path, AssemblyResolutionResult result, ReferenceAssemblyType assemblyType) { lock (s_lock) { if (!AssemblyLocations.ContainsKey(a)) { AssemblyLocations.Add(a, path); AssemblyResolutionResults.Add(a, result); ReferenceAssemblyTypes.Add(a, assemblyType); } } }