private static ReferenceAssemblyType GetPathToReferenceAssembly(Assembly a, out string path, ICollection <BuildErrorEventArgs> errors, ICollection <BuildWarningEventArgs> warnings, bool checkDependencies, bool useFullName, out AssemblyResolutionResult result) { string originalAssemblyName; string name = a.GetName().Name; if (useFullName) { originalAssemblyName = CompilationSection.GetOriginalAssemblyName(a); } else { originalAssemblyName = name; } result = ResolveAssembly(originalAssemblyName, TargetFrameworkReferenceAssemblyPaths, TargetFrameworkReferenceAssemblyPaths, false); if ((result.ResolvedFiles != null) && (result.ResolvedFiles.Count > 0)) { path = result.ResolvedFiles.FirstOrDefault <string>(); FixMscorlibPath(a, ref path); return(ReferenceAssemblyType.FrameworkAssembly); } result = ResolveAssembly(originalAssemblyName, HigherFrameworkReferenceAssemblyPaths, HigherFrameworkReferenceAssemblyPaths, false); if ((result.ResolvedFiles != null) && (result.ResolvedFiles.Count > 0)) { path = result.ResolvedFiles.FirstOrDefault <string>(); return(ReferenceAssemblyType.FrameworkAssemblyOnlyPresentInHigherVersion); } if (NeedToCheckFullProfile) { result = ResolveAssembly(originalAssemblyName, FullProfileReferenceAssemblyPaths, FullProfileReferenceAssemblyPaths, false); if ((result.ResolvedFiles != null) && (result.ResolvedFiles.Count > 0)) { path = result.ResolvedFiles.FirstOrDefault <string>(); string str3 = ""; if (!string.IsNullOrEmpty(MultiTargetingUtil.TargetFrameworkName.Profile)) { str3 = " '" + MultiTargetingUtil.TargetFrameworkName.Profile + "'"; } ReportWarningOrError(System.Web.SR.GetString("Assembly_not_found_in_profile", new object[] { originalAssemblyName, str3 })); return(ReferenceAssemblyType.FrameworkAssemblyOnlyPresentInHigherVersion); } } List <string> searchPaths = new List <string>(); searchPaths.AddRange(TargetFrameworkReferenceAssemblyPaths); searchPaths.Add(Path.GetDirectoryName(a.Location)); if (useFullName) { searchPaths.Add("{GAC}"); } if (!useFullName) { originalAssemblyName = a.GetName().FullName; } result = ResolveAssembly(originalAssemblyName, searchPaths, TargetFrameworkReferenceAssemblyPaths, checkDependencies); path = result.ResolvedFiles.FirstOrDefault <string>(); if (string.IsNullOrEmpty(path)) { path = Util.GetAssemblyCodeBase(a); } if (useFullName) { AssemblyResolutionResult result2 = ResolveAssembly(name, HigherFrameworkReferenceAssemblyPaths, HigherFrameworkReferenceAssemblyPaths, false); if ((result2.ResolvedFiles != null) && (result2.ResolvedFiles.Count > 0)) { return(ReferenceAssemblyType.FrameworkAssembly); } } return(ReferenceAssemblyType.NonFrameworkAssembly); }
private static ReferenceAssemblyType GetPathToReferenceAssembly(Assembly a, out string path, ICollection <BuildErrorEventArgs> errors, ICollection <BuildWarningEventArgs> warnings, bool checkDependencies, bool useFullName, out AssemblyResolutionResult result) { // 1. Find the assembly using RAR in the target framework. // - If found, assembly is a framework assembly. Done // 2. Find the assembly using RAR in higher frameworks. // - If found, assembly is a framework assembly only present in a higher version. Done. // 3. Find the assembly using RAR in the full profile framework. // - If found, assembly is a framework assembly, but is only present in the full profile framework and not the current target profile. Done. // 4. Is useFullName true? // - Yes: Use GAC and directory of loaded assembly as search paths. // - No: Use directory of loaded assembly as search path. // - Use RAR to find assembly in search paths. // - Check for out of range dependencies. // 5. If useFullName // - Check if the short name exists in a higher framework, if so, it is a framework assembly. // Find the assembly in the target framework. string assemblyName; string partialName = a.GetName().Name; if (useFullName) { // Use the actual assembly name as specified in the config. assemblyName = CompilationSection.GetOriginalAssemblyName(a); } else { assemblyName = partialName; } result = ResolveAssembly(assemblyName, TargetFrameworkReferenceAssemblyPaths, TargetFrameworkReferenceAssemblyPaths, false /*checkDependencies*/); if (result.ResolvedFiles != null && result.ResolvedFiles.Count > 0) { path = result.ResolvedFiles.FirstOrDefault(); return(ReferenceAssemblyType.FrameworkAssembly); } // At this point, the assembly was not found in the target framework. // Try finding it in the latest framework. result = ResolveAssembly(assemblyName, HigherFrameworkReferenceAssemblyPaths, HigherFrameworkReferenceAssemblyPaths, false /*checkDependencies*/); if (result.ResolvedFiles != null && result.ResolvedFiles.Count > 0) { path = result.ResolvedFiles.FirstOrDefault(); // Assembly was found in a target framework of a later version. return(ReferenceAssemblyType.FrameworkAssemblyOnlyPresentInHigherVersion); } // Try to find the assembly in the full profile, in case the user // is using an assembly that is not in the target profile framework. // For example, System.Web is not present in the Client profile, but is present in the full profile. if (NeedToCheckFullProfile) { result = ResolveAssembly(assemblyName, FullProfileReferenceAssemblyPaths, FullProfileReferenceAssemblyPaths, false /*checkDependencies*/); if (result.ResolvedFiles != null && result.ResolvedFiles.Count > 0) { // Assembly was found in the full profile, but not in the target profile. path = result.ResolvedFiles.FirstOrDefault(); // Report warning/error message. string profile = ""; if (!string.IsNullOrEmpty(MultiTargetingUtil.TargetFrameworkName.Profile)) { profile = " '" + MultiTargetingUtil.TargetFrameworkName.Profile + "'"; } ReportWarningOrError(SR.GetString(SR.Assembly_not_found_in_profile, assemblyName, profile)); // Return as OnlyPresentInHigherVersion so that it will not be used as a reference assembly. return(ReferenceAssemblyType.FrameworkAssemblyOnlyPresentInHigherVersion); } } // Assembly is not found in the framework. // Check whether it has any references to assemblies of a higher version. List <string> searchPaths = new List <string>(); searchPaths.AddRange(TargetFrameworkReferenceAssemblyPaths); searchPaths.Add(Path.GetDirectoryName(a.Location)); // If we are using full names, include the GAC so that we can retrieve the actual // specified version of an OOB assembly even if it is unified/redirected to a later version. // For example, System.Web.Extensions 1.0.61025 is available from the GAC, but the actual // loaded assembly is 4.0 due to unification. if (useFullName) { searchPaths.Add("{GAC}"); } // When checking dependencies of a custom assembly, use the full // name of the assembly as it might have a strong name or // be in the GAC. if (!useFullName) { assemblyName = a.GetName().FullName; } result = ResolveAssembly(assemblyName, searchPaths, TargetFrameworkReferenceAssemblyPaths, checkDependencies); // Use the actual resolved path, in case the loaded assembly is different from the specified assembly // due to unification or binding redirect. path = result.ResolvedFiles.FirstOrDefault(); if (string.IsNullOrEmpty(path)) { // In some cases, we might not be able to resolve the path to the assembly successfully, for example when // the config specifies the full name as System.Web 4.0.10101.0. Assembly.Load returns the 4.0.0.0 version, // but we can't find any actual assembly with such a full name. path = System.Web.UI.Util.GetAssemblyCodeBase(a); } // If we are using full names, do another check using the partial name to see if the assembly is part of // a higher framework. // If so, then this is an OOB assembly that later got rolled into the framework, so we consider the assembly // as a framework assembly. if (useFullName) { AssemblyResolutionResult r = ResolveAssembly(partialName, HigherFrameworkReferenceAssemblyPaths, HigherFrameworkReferenceAssemblyPaths, false /*checkDependencies*/); if (r.ResolvedFiles != null && r.ResolvedFiles.Count > 0) { return(ReferenceAssemblyType.FrameworkAssembly); } } return(ReferenceAssemblyType.NonFrameworkAssembly); }