public virtual AssemblyNode ResolveReference(AssemblyReference reference, Module module) { if (reference == null) throw new ArgumentNullException("reference"); //Console.WriteLine("resolving {0}", reference.StrongName); // try to get it from the cache string name = reference.StrongName; if (cache.ContainsKey(name)) return (cache[name]); // try to get it from the gac if (useGac) { string location = GlobalAssemblyCache.GetLocation(reference); if (location != null) { AssemblyNode assembly = AssemblyNode.GetAssembly(location, null, false, false, false, false); if (assembly != null) { Add(assembly); return (assembly); } } } // couldn't find it; return null // Console.WriteLine("returning null on request for {0}", reference.StrongName); //OnUnresolvedAssemblyReference(reference, module); return (null); }
/// <summary> /// Returns the original location of the corresponding assembly if available, otherwise returns the /// location of the shadow copy. If the corresponding assembly is not in the GAC, null is returned. /// </summary> public static string GetLocation(AssemblyReference assemblyReference) { if(assemblyReference == null) { Debug.Fail("assemblyReference == null"); return null; } lock(GlobalAssemblyCache.Lock) { if(!GlobalAssemblyCache.FusionLoaded) { GlobalAssemblyCache.FusionLoaded = true; System.Reflection.Assembly systemAssembly = typeof(object).Assembly; //^ assume systemAssembly != null && systemAssembly.Location != null; string dir = Path.GetDirectoryName(systemAssembly.Location); //^ assume dir != null; GlobalAssemblyCache.LoadLibrary(Path.Combine(dir, "fusion.dll")); } IAssemblyEnum assemblyEnum; CreateAssemblyEnum(out assemblyEnum, null, null, GAC, 0); if(assemblyEnum == null) return null; IApplicationContext applicationContext; IAssemblyName currentName; while(assemblyEnum.GetNextAssembly(out applicationContext, out currentName, 0) == 0) { //^ assume currentName != null; AssemblyName aName = new AssemblyName(currentName); if(assemblyReference.Matches(aName.Name, aName.Version, aName.Culture, aName.PublicKeyToken)) { string codeBase = aName.CodeBase; if(codeBase != null && codeBase.StartsWith("file:///")) return codeBase.Substring(8); return aName.GetLocation(); } } return null; } }
public static void SetToV2(string platformAssembliesLocation) { TargetPlatform.TargetVersion = new Version(2, 0, 50727); TargetPlatform.TargetRuntimeVersion = "v2.0.50727"; TargetPlatform.GenericTypeNamesMangleChar = '`'; if (platformAssembliesLocation == null || platformAssembliesLocation.Length == 0) platformAssembliesLocation = TargetPlatform.PlatformAssembliesLocation = Path.Combine(Path.GetDirectoryName(typeof(object).Module.Assembly.Location), "..\\v2.0.50727"); else TargetPlatform.PlatformAssembliesLocation = platformAssembliesLocation; TargetPlatform.PlatformAssembliesLocation = platformAssembliesLocation; TargetPlatform.InitializeStandardAssemblyLocationsWithDefaultValues(platformAssembliesLocation); TrivialHashtable assemblyReferenceFor = new TrivialHashtable(46); for (int i = 0, n = TargetPlatform.FxAssemblyNames.Length; i < n; i++) { string name = TargetPlatform.FxAssemblyNames[i]; string version = TargetPlatform.FxAssemblyVersion2[i]; string token = TargetPlatform.FxAssemblyToken[i]; AssemblyReference aref = new AssemblyReference(name + ", Version=" + version + ", Culture=neutral, PublicKeyToken=" + token); aref.Location = platformAssembliesLocation + "\\" + name + ".dll"; //^ assume name != null; assemblyReferenceFor[Identifier.For(name).UniqueIdKey] = aref; } TargetPlatform.assemblyReferenceFor = assemblyReferenceFor; }
/// <summary> /// Resolves assembly references based on the library paths specified. /// Tries to resolve to ".dll" or ".exe". First found wins. /// </summary> /// <param name="assemblyReference">Reference to resolve.</param> /// <param name="referencingModule">Referencing module.</param> /// <returns>The resolved assembly node (null if not found).</returns> private static AssemblyNode AssemblyReferenceResolution (AssemblyReference assemblyReference, Module referencingModule) { AssemblyNode a = ProbeForAssembly(assemblyReference.Name, referencingModule.Directory, DllAndExeExt); return a; }
/// <summary> /// This is used to try and resolve an assembly reference /// </summary> /// <param name="reference">The assembly reference</param> /// <param name="referrer">The module requiring the reference</param> /// <returns>The assembly node if resolved or null if not resolved</returns> public virtual AssemblyNode ResolveReference(AssemblyReference reference, Module referrer) { AssemblyNode assembly; if(reference == null) throw new ArgumentNullException("reference"); // Try to get it from the cache string name = reference.StrongName; if(cache.ContainsKey(name)) return cache[name]; // Try to get it from the GAC if so indicated if(this.UseGac) { string location = GlobalAssemblyCache.GetLocation(reference); if(location != null) { assembly = AssemblyNode.GetAssembly(location, null, false, false, false, false); if(assembly != null) { this.Add(assembly); return assembly; } } } // Try the redirects if not found foreach(BindingRedirectSettings brs in redirects) if(brs.IsRedirectFor(name) && cache.ContainsKey(brs.StrongName)) { ConsoleApplication.WriteMessage(LogLevel.Info, "Using redirect '{0}' in place of '{1}'", brs.StrongName, name); assembly = cache[brs.StrongName]; // Add the same assembly under the current name cache.Add(name, assembly); return assembly; } // Couldn't find it; return null return null; }
public override AssemblyReference VisitAssemblyReference(AssemblyReference assemblyReference) { if (assemblyReference == null) return null; return base.VisitAssemblyReference((AssemblyReference)assemblyReference.Clone()); }
private static AssemblyNode/*!*/ GetSystemXmlAssembly(bool doNotLockFile, bool getDebugInfo) { System.Reflection.AssemblyName aName = typeof(System.Xml.XmlNode).Module.Assembly.GetName(); Identifier SystemXmlId = Identifier.For(aName.Name); AssemblyReference aref = (AssemblyReference)TargetPlatform.AssemblyReferenceFor[SystemXmlId.UniqueIdKey]; if (aref == null) { aref = new AssemblyReference(); aref.Name = aName.Name; aref.PublicKeyOrToken = aName.GetPublicKeyToken(); aref.Version = TargetPlatform.TargetVersion; TargetPlatform.AssemblyReferenceFor[SystemXmlId.UniqueIdKey] = aref; } if (SystemXmlAssemblyLocation.Location == null || SystemXmlAssemblyLocation.Location.Length == 0) SystemXmlAssemblyLocation.Location = typeof(System.Xml.XmlNode).Module.Assembly.Location; if (aref.assembly == null) aref.Location = SystemXmlAssemblyLocation.Location; return aref.assembly = AssemblyNode.GetAssembly(aref); }
/// <summary> /// Resolves assembly references based on the library paths specified. /// Tries to resolve to ".dll" or ".exe". First found wins. /// </summary> /// <param name="assemblyReference">Reference to resolve.</param> /// <param name="referencingModule">Referencing module.</param> /// <returns>The resolved assembly node (null if not found).</returns> public AssemblyNode ResolveAssemblyReference(AssemblyReference assemblyReference, Module referencingModule) { AssemblyNode a = ProbeForAssembly(assemblyReference.Name, referencingModule.Directory, DllAndExeExt); return a; }
public static AssemblyNode GetAssembly(AssemblyReference assemblyReference) { return AssemblyNode.GetAssembly(assemblyReference, null, false, false, true, false); }
public virtual AssemblyNode ResolveAfterProbingFailed(AssemblyReference assemblyReference) { if(this.AssemblyReferenceResolutionAfterProbingFailed == null) return null; return this.AssemblyReferenceResolutionAfterProbingFailed(assemblyReference, this); }
public virtual AssemblyNode Resolve(AssemblyReference assemblyReference) { if(this.AssemblyReferenceResolution == null) return null; return this.AssemblyReferenceResolution(assemblyReference, this); }
//===================================================================== /// <summary> /// This is overridden to resolve unknown assembly references /// </summary> /// <param name="reference">The reference to resolve</param> /// <param name="module">The module</param> /// <returns>The assembly node if resolved or null if not resolved</returns> public override AssemblyNode ResolveReference( AssemblyReference reference, System.Compiler.Module module) { AssemblyNode node = base.ResolveReference(reference, module); string name; // Try the redirects if not found if(node == null) { name = reference.StrongName; foreach(BindingRedirectSettings brs in redirects) if(brs.IsRedirectFor(name) && cache.ContainsKey(brs.StrongName)) { ConsoleApplication.WriteMessage(LogLevel.Info, "Using redirect '{0}' in place of '{1}'", brs.StrongName, name); node = cache[brs.StrongName]; cache.Add(name, node); break; } } return node; }
/// <summary> /// Constructor /// </summary> /// <param name="reference">The assembly reference needed</param> /// <param name="referrer">The module requiring the reference</param> public AssemblyReferenceEventArgs(AssemblyReference reference, Module referrer) { this.Reference = reference; this.Referrer = referrer; }
public AssemblyReferenceEventArgs(AssemblyReference reference, Module module) { this.reference = reference; this.module = module; }
public static void SetToV2Beta1(string/*!*/ platformAssembliesLocation) { TargetPlatform.TargetVersion = new Version(2, 0, 3600); TargetPlatform.GenericTypeNamesMangleChar = '!'; string dotNetDirLocation = null; if (platformAssembliesLocation == null || platformAssembliesLocation.Length == 0) { DirectoryInfo dotNetDir = new FileInfo(new Uri(typeof(object).Module.Assembly.Location).LocalPath).Directory.Parent; dotNetDirLocation = dotNetDir.FullName; if (dotNetDirLocation != null) dotNetDirLocation = dotNetDirLocation.ToUpper(System.Globalization.CultureInfo.InvariantCulture); DateTime creationTime = DateTime.MinValue; foreach (DirectoryInfo subdir in dotNetDir.GetDirectories("v2.0*")) { if (subdir == null) continue; if (subdir.CreationTime < creationTime) continue; FileInfo[] mscorlibs = subdir.GetFiles("mscorlib.dll"); if (mscorlibs != null && mscorlibs.Length == 1) { platformAssembliesLocation = subdir.FullName; creationTime = subdir.CreationTime; } } } else TargetPlatform.PlatformAssembliesLocation = platformAssembliesLocation; if (dotNetDirLocation != null && (platformAssembliesLocation == null || platformAssembliesLocation.Length == 0)) { int pos = dotNetDirLocation.IndexOf("FRAMEWORK"); if (pos > 0 && dotNetDirLocation.IndexOf("FRAMEWORK64") < 0) { dotNetDirLocation = dotNetDirLocation.Replace("FRAMEWORK", "FRAMEWORK64"); if (Directory.Exists(dotNetDirLocation)) { DirectoryInfo dotNetDir = new DirectoryInfo(dotNetDirLocation); DateTime creationTime = DateTime.MinValue; foreach (DirectoryInfo subdir in dotNetDir.GetDirectories("v2.0*")) { if (subdir == null) continue; if (subdir.CreationTime < creationTime) continue; FileInfo[] mscorlibs = subdir.GetFiles("mscorlib.dll"); if (mscorlibs != null && mscorlibs.Length == 1) { platformAssembliesLocation = subdir.FullName; creationTime = subdir.CreationTime; } } } } } TargetPlatform.PlatformAssembliesLocation = platformAssembliesLocation; TargetPlatform.InitializeStandardAssemblyLocationsWithDefaultValues(platformAssembliesLocation); TrivialHashtable assemblyReferenceFor = new TrivialHashtable(46); for (int i = 0, n = TargetPlatform.FxAssemblyNames.Length; i < n; i++) { string name = TargetPlatform.FxAssemblyNames[i]; string version = TargetPlatform.FxAssemblyVersion2Build3600[i]; string token = TargetPlatform.FxAssemblyToken[i]; AssemblyReference aref = new AssemblyReference(name + ", Version=" + version + ", Culture=neutral, PublicKeyToken=" + token); aref.Location = platformAssembliesLocation + "\\" + name + ".dll"; //^ assume name != null; assemblyReferenceFor[Identifier.For(name).UniqueIdKey] = aref; } TargetPlatform.assemblyReferenceFor = assemblyReferenceFor; }
protected virtual void OnUnresolvedAssemblyReference(AssemblyReference reference, Module module) { if (UnresolvedAssemblyReference != null) UnresolvedAssemblyReference(this, new AssemblyReferenceEventArgs(reference, module)); }
private AssemblyNode UnresolvedReference(AssemblyReference reference, Module module) { OnUnresolvedAssemblyReference(reference, module); return (null); }
public static AssemblyNode GetAssembly(AssemblyReference assemblyReference, IDictionary cache) { return AssemblyNode.GetAssembly(assemblyReference, cache, false, false, false, false); }
private static AssemblyNode AssemblyNotFound(AssemblyReference reference, System.Compiler.Module module) { ConsoleApplication.WriteMessage(LogLevel.Error, String.Format("Unresolved assembly reference: {0} ({1}) required by {2}", reference.Name, reference.StrongName, module.Name)); Environment.Exit(1); return (null); }
public static AssemblyNode GetAssembly(AssemblyReference assemblyReference, IDictionary cache, bool doNotLockFile, bool getDebugInfo, bool useGlobalCache) { return AssemblyNode.GetAssembly(assemblyReference, cache, doNotLockFile, getDebugInfo, useGlobalCache, false); }
//!EFW /// <summary> /// Load target framework settings and assembly details /// </summary> /// <param name="platformType">The platform type</param> /// <param name="version">The framework version</param> public static void SetFrameworkInformation(string platformType, string version) { var fs = Sandcastle.Core.Frameworks.FrameworkDictionary.AllFrameworks.FrameworkMatching( platformType, new Version(version), true); if(fs == null) throw new InvalidOperationException(String.Format("Unable to locate information for the " + "framework version '{0} {1}' or a suitable redirected version on this system", platformType, version)); var coreLocation = fs.AssemblyLocations.First(l => l.IsCoreLocation); if(coreLocation == null) throw new InvalidOperationException(String.Format("A core framework location has not been " + "defined for the framework '{0} {1}'", platformType, version)); TargetPlatform.Platform = fs.Platform; TargetPlatform.TargetVersion = fs.Version; TargetPlatform.TargetRuntimeVersion = "v" + fs.Version.ToString(); TargetPlatform.GenericTypeNamesMangleChar = '`'; TargetPlatform.PlatformAssembliesLocation = coreLocation.Path; // Set references to the common core framework assemblies var ad = fs.FindAssembly("mscorlib"); if(ad != null) SystemAssemblyLocation.Location = ad.Filename; ad = fs.FindAssembly("System.Data"); if(ad != null) SystemDataAssemblyLocation.Location = ad.Filename; ad = fs.FindAssembly("System.Xml"); if(ad != null) SystemXmlAssemblyLocation.Location = ad.Filename; // Load references to all the other framework assemblies var allAssemblies = fs.AllAssemblies.ToList(); TrivialHashtable assemblyReferenceFor = new TrivialHashtable(allAssemblies.Count); // Loading mscorlib causes a reset of the reference cache and other info so we must ignore it. foreach(var asm in allAssemblies) if(!asm.Name.Equals("mscorlib", StringComparison.OrdinalIgnoreCase) && File.Exists(asm.Filename)) { AssemblyReference aref = new AssemblyReference(asm.ToString()); aref.Location = asm.Filename; assemblyReferenceFor[Identifier.For(asm.Name).UniqueIdKey] = aref; } TargetPlatform.assemblyReferenceFor = assemblyReferenceFor; }
public static AssemblyNode GetAssembly(AssemblyReference assemblyReference, IDictionary cache, bool doNotLockFile, bool getDebugInfo, bool useGlobalCache, bool preserveShortBranches) { if(assemblyReference == null) return null; if(CoreSystemTypes.SystemAssembly == null) Debug.Fail(""); Reader reader = new Reader(cache, doNotLockFile, getDebugInfo, useGlobalCache, preserveShortBranches); return assemblyReference.Assembly = reader.GetAssemblyFromReference(assemblyReference); }
/// <summary> /// This raises the <see cref="UnresolvedAssemblyReference" event/> /// </summary> /// <param name="reference">The assembly reference</param> /// <param name="referrer">The module requiring the reference</param> protected virtual void OnUnresolvedAssemblyReference(AssemblyReference reference, Module referrer) { var handler = UnresolvedAssemblyReference; if(handler != null) handler(this, new AssemblyReferenceEventArgs(reference, referrer)); }
public virtual bool MayAccessInternalTypesOf(AssemblyNode assembly) { if(this == assembly) return true; if(assembly == null || SystemTypes.InternalsVisibleToAttribute == null) return false; if(this.friends == null) this.friends = new TrivialHashtable(); object ob = this.friends[assembly.UniqueKey]; if(ob == (object)string.Empty) return false; if(ob == this) return true; AttributeList attributes = assembly.Attributes; for(int i = 0, n = attributes == null ? 0 : attributes.Count; i < n; i++) { //^ assert attributes != null; AttributeNode attr = attributes[i]; if(attr == null) continue; MemberBinding mb = attr.Constructor as MemberBinding; if(mb != null) { if(mb.BoundMember == null) continue; if(mb.BoundMember.DeclaringType != SystemTypes.InternalsVisibleToAttribute) continue; } else { Literal lit = attr.Constructor as Literal; if(lit == null) continue; if((lit.Value as TypeNode) != SystemTypes.InternalsVisibleToAttribute) continue; } if(attr.Expressions == null || attr.Expressions.Count < 1) continue; Literal argLit = attr.Expressions[0] as Literal; if(argLit == null) continue; string friendName = argLit.Value as string; if(friendName == null) continue; try { AssemblyReference ar = new AssemblyReference(friendName); byte[] tok = ar.PublicKeyToken; if(tok != null && this.PublicKeyOrToken != null) tok = this.PublicKeyToken; if(!ar.Matches(this.Name, ar.Version, ar.Culture, tok)) continue; } catch(ArgumentException e) { if(this.MetadataImportErrors == null) this.MetadataImportErrors = new ArrayList(); this.MetadataImportErrors.Add(e.Message); continue; } this.friends[assembly.UniqueKey] = this; return true; } this.friends[assembly.UniqueKey] = string.Empty; return false; }
/// <summary> /// This is called if assembly reference resolution fails after probing /// </summary> /// <param name="reference">The assembly reference</param> /// <param name="module">The module</param> /// <returns>Always returns null</returns> private AssemblyNode UnresolvedReference(AssemblyReference reference, Module module) { // Don't raise the event if ignored if(!ignoreIfUnresolved.Contains(reference.Name)) OnUnresolvedAssemblyReference(reference, module); else ConsoleApplication.WriteMessage(LogLevel.Warn, "Ignoring unresolved assembly " + "reference: {0} ({1}) required by {2}", reference.Name, reference.StrongName, module.Name); return null; }
public bool MatchesIgnoringVersion(AssemblyReference reference) { if(reference == null) return false; return this.Matches(reference.Name, this.Version, reference.Culture, reference.PublicKeyToken); }
public string GetVersionFromStrongName(string name) { AssemblyReference ar = new AssemblyReference(name); return ar.Version.ToString(); }
public override AssemblyNode ResolveReference(AssemblyReference reference, Module module) { Console.WriteLine("test resolver: {0}", reference.StrongName); return (base.ResolveReference(reference, module)); }
public virtual AssemblyReference VisitAssemblyReference(AssemblyReference assemblyReference) { return assemblyReference; }
public override AssemblyReference VisitAssemblyReference(AssemblyReference assemblyReference) { throw new NotImplementedException("Node type not yet supported"); }