static string GetVersion__Token(DomAssemblyName asmName) { StringBuilder b = new StringBuilder(asmName.Version.ToString()); b.Append("__"); b.Append(asmName.PublicKeyToken); return(b.ToString()); }
static string GetAssemblyFile(DomAssemblyName reference, string prefix, string gac) { var gac_folder = new StringBuilder() .Append(prefix) .Append(reference.Version) .Append("__"); gac_folder.Append(reference.PublicKeyToken); return(Path.Combine( Path.Combine( Path.Combine(gac, reference.ShortName), gac_folder.ToString()), reference.ShortName + ".dll")); }
public ReflectionProjectContent(Assembly assembly, string assemblyLocation, ProjectContentRegistry registry) : this(assembly.FullName, assemblyLocation, DomAssemblyName.Convert(assembly.GetReferencedAssemblies()), registry) { foreach (Type type in assembly.GetExportedTypes()) { string name = type.FullName; if (name.IndexOf('+') < 0) // type.IsNested { AddClassToNamespaceListInternal(new ReflectionClass(assemblyCompilationUnit, type, name, null)); } } InitializeSpecialClasses(); AddAssemblyAttributes(assembly); assemblyCompilationUnit.Freeze(); }
public ReflectionProjectContent ReadProjectContent(ProjectContentRegistry registry) { if (reader.ReadInt64() != FileMagic) { LoggingService.Warn("Read dom: wrong magic"); return(null); } if (reader.ReadInt16() != FileVersion) { LoggingService.Warn("Read dom: wrong version"); return(null); } string assemblyName = reader.ReadString(); string assemblyLocation = reader.ReadString(); long time = 0; try { time = File.GetLastWriteTimeUtc(assemblyLocation).ToFileTime(); } catch {} if (reader.ReadInt64() != time) { LoggingService.Warn("Read dom: assembly changed since cache was created"); return(null); } DomAssemblyName[] referencedAssemblies = new DomAssemblyName[reader.ReadInt32()]; for (int i = 0; i < referencedAssemblies.Length; i++) { referencedAssemblies[i] = new DomAssemblyName(reader.ReadString()); } this.pc = new ReflectionProjectContent(assemblyName, assemblyLocation, referencedAssemblies, registry); if (ReadClasses()) { return(pc); } else { LoggingService.Warn("Read dom: error in file (invalid control mark)"); return(null); } }
/// <summary> /// Gets the file name for an assembly stored in the GAC. /// </summary> public static string FindAssemblyInNetGac(DomAssemblyName reference) { // without public key, it can't be in the GAC if (reference.PublicKeyToken == null) { return(null); } for (int i = 0; i < 2; i++) { for (int j = 0; j < gacs.Length; j++) { var gac = Path.Combine(gac_paths [i], gacs [j]); var file = GetAssemblyFile(reference, prefixes [i], gac); if (File.Exists(file)) { return(file); } } } return(null); }
protected virtual IProjectContent LoadProjectContent(string itemInclude, string itemFileName) { string shortName = itemInclude; int pos = shortName.IndexOf(','); if (pos > 0) { shortName = shortName.Substring(0, pos); } Assembly assembly = GetDefaultAssembly(shortName); ReflectionProjectContent pc = null; if (assembly != null) { if (persistence != null) { pc = persistence.LoadProjectContentByAssemblyName(assembly.FullName); } if (pc == null) { pc = new ReflectionProjectContent(assembly, this); if (persistence != null) { persistence.SaveProjectContent(pc); } } } else { // find real file name for cecil: if (File.Exists(itemFileName)) { if (persistence != null) { pc = persistence.LoadProjectContentByAssemblyName(itemFileName); } if (pc == null) { pc = CecilReader.LoadAssembly(itemFileName, this); if (persistence != null) { persistence.SaveProjectContent(pc); } } } else { DomAssemblyName asmName = GacInterop.FindBestMatchingAssemblyName(itemInclude); if (persistence != null && asmName != null) { //LoggingService.Debug("Looking up in DOM cache: " + asmName.FullName); pc = persistence.LoadProjectContentByAssemblyName(asmName.FullName); } if (pc == null && asmName != null) { string subPath = Path.Combine(asmName.ShortName, GetVersion__Token(asmName)); subPath = Path.Combine(subPath, asmName.ShortName + ".dll"); foreach (string dir in Directory.GetDirectories(GacInterop.GacRootPathV4, "GAC*")) { itemFileName = Path.Combine(dir, subPath); if (File.Exists(itemFileName)) { pc = CecilReader.LoadAssembly(itemFileName, this); if (persistence != null) { persistence.SaveProjectContent(pc); } break; } } } if (pc == null) { HostCallback.ShowAssemblyLoadErrorInternal(itemFileName, itemInclude, "Could not find assembly file."); } } } return(pc); }
public IProjectContent GetExistingProjectContent(DomAssemblyName assembly) { return(GetExistingProjectContent(assembly.FullName)); }
IProjectContent GetExistingProjectContent(IProjectContent[] existingProjectContents, DomAssemblyName fullAssemblyName) { IProjectContent content = registry.GetExistingProjectContent(fullAssemblyName); if (content != null) { return(content); } else if (existingProjectContents.Any()) { return(GetExistingProjectContentForShortName(existingProjectContents, fullAssemblyName.ShortName)); } return(null); }
public static DomAssemblyName FindBestMatchingAssemblyName(DomAssemblyName name) { string[] info; Version requiredVersion = name.Version; string publicKey = name.PublicKeyToken; IApplicationContext applicationContext = null; IAssemblyEnum assemblyEnum = null; IAssemblyName assemblyName; Fusion.CreateAssemblyNameObject(out assemblyName, name.ShortName, 0, 0); Fusion.CreateAssemblyEnum(out assemblyEnum, null, assemblyName, 2, 0); List <string> names = new List <string>(); while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0) { uint nChars = 0; assemblyName.GetDisplayName(null, ref nChars, 0); StringBuilder sb = new StringBuilder((int)nChars); assemblyName.GetDisplayName(sb, ref nChars, 0); string fullName = sb.ToString(); if (publicKey != null) { info = fullName.Split(','); if (publicKey != info[3].Substring(info[3].LastIndexOf('=') + 1)) { // Assembly has wrong public key continue; } } names.Add(fullName); } if (names.Count == 0) { return(null); } string best = null; Version bestVersion = null; Version currentVersion; if (requiredVersion != null) { // use assembly with lowest version higher or equal to required version for (int i = 0; i < names.Count; i++) { info = names[i].Split(','); currentVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1)); if (currentVersion.CompareTo(requiredVersion) < 0) { continue; // version not good enough } if (best == null || currentVersion.CompareTo(bestVersion) < 0) { bestVersion = currentVersion; best = names[i]; } } if (best != null) { return(new DomAssemblyName(best)); } } // use assembly with highest version best = names[0]; info = names[0].Split(','); bestVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1)); for (int i = 1; i < names.Count; i++) { info = names[i].Split(','); currentVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1)); if (currentVersion.CompareTo(bestVersion) > 0) { bestVersion = currentVersion; best = names[i]; } } return(new DomAssemblyName(best)); }