public string GetTargetFrameworkForAssembly(TargetRuntime tr, string file) { try { AssemblyDefinition asm = AssemblyFactory.GetAssemblyManifest(file); AssemblyNameReferenceCollection names = asm.MainModule.AssemblyReferences; foreach (AssemblyNameReference aname in names) { if (aname.Name == "mscorlib") { foreach (TargetFramework tf in GetTargetFrameworks()) { if (tf.GetCorlibVersion() == aname.Version.ToString()) { return(tf.Id); } } break; } } } catch { // Ignore } return("FxUnknown"); }
public IEnumerable <string> ReadAssemblyReferences() { AssemblyDefinition asm = AssemblyFactory.GetAssemblyManifest(assemblyFile); AssemblyNameReferenceCollection names = asm.MainModule.AssemblyReferences; foreach (AssemblyNameReference aname in names) { string afile = runtime.AssemblyContext.GetAssemblyLocation(aname.FullName, fx); if (afile != null) { yield return("Assembly:" + runtime.Id + ":" + Path.GetFullPath(afile)); } } }
public static bool isDotNetAssembly(string assemblyToCheck, bool verbose) { try { AssemblyDefinition assemblyManifest = AssemblyFactory.GetAssemblyManifest(assemblyToCheck); //var assembly = loadAssembly(assemblyToCheck); if (assemblyManifest == null) { return(false); } return(true); } catch (Exception ex) { if (verbose) { DI.log.error("in CecilUtils.isDotNetAssembly: while processing {0} this error occured: {1}", assemblyToCheck, ex.Message); } return(false); } }
internal static System.Reflection.AssemblyName GetAssemblyNameObj(string file) { try { AssemblyDefinition asm = AssemblyFactory.GetAssemblyManifest(file); return(new AssemblyName(asm.Name.FullName)); // Don't use reflection to get the name since it is a common cause for deadlocks // in Mono < 2.6. // return System.Reflection.AssemblyName.GetAssemblyName (file); } catch (FileNotFoundException) { // GetAssemblyName is not case insensitive in mono/windows. This is a workaround foreach (string f in Directory.GetFiles(Path.GetDirectoryName(file), Path.GetFileName(file))) { if (f != file) { return(GetAssemblyNameObj(f)); } } throw; } catch (BadImageFormatException) { AssemblyDefinition asm = AssemblyFactory.GetAssemblyManifest(file); return(new AssemblyName(asm.Name.FullName)); } }