public static bool IsAssemblyExist(string name, string version) { var assemblyEnumerator = new AssemblyCacheEnumerator(); // Get the first assembly. var assemblyName = assemblyEnumerator.GetNextAssembly(); // Start to loop through the assemblies. while (assemblyName != null) { // The 'assemblyName' object is a COM interface, if we create an // AssemblyDescription from it, we will have access to more information. var assemblyDescription = new AssemblyDescription(assemblyName); if (assemblyDescription.Name.ToUpper().Trim() == name.ToUpper().Trim() && assemblyDescription.Version.Trim() == version.Trim()) { return true; } // Move to the next assembly. assemblyName = assemblyEnumerator.GetNextAssembly(); } return false; }
private AssemblyFusionProperties DoLoadFusionProperties() { // Use the enumerator to get the assembly name. var enumerator = new AssemblyCacheEnumerator(DisplayName); var assemblyName = enumerator.GetNextAssembly(); // Return the properties. return(DoLoadFusionProperties(assemblyName)); }
public static List<AssemblyDescription> GetAllGACAssembly() { var list = new List<AssemblyDescription>(); var assemblyEnumerator = new AssemblyCacheEnumerator(); // Get the first assembly. var assemblyName = assemblyEnumerator.GetNextAssembly(); // Start to loop through the assemblies. while (assemblyName != null) { // The 'assemblyName' object is a COM interface, if we create an // AssemblyDescription from it, we will have access to more information. var assemblyDescription = new AssemblyDescription(assemblyName); list.Add(assemblyDescription); // Move to the next assembly. assemblyName = assemblyEnumerator.GetNextAssembly(); } return list; }
private AssemblyFusionProperties DoLoadFusionProperties() { // Use the enumerator to get the assembly name. var enumerator = new AssemblyCacheEnumerator(DisplayName); var assemblyName = enumerator.GetNextAssembly(); // Return the properties. return DoLoadFusionProperties(assemblyName); }
public static List<DotnetLibrary> GetGACLibraries() { var gacList = new List<DotnetLibrary>(); try { var assemblyEnumerator = new AssemblyCacheEnumerator(); var assemblyName = assemblyEnumerator.GetNextAssembly(); while (assemblyName != null) { var assemblyDescription = new AssemblyDescription(assemblyName); string name = assemblyDescription.Name; bool probablyMicrosoftPackage = (name.StartsWith("Microsoft") || name.StartsWith("System")); if (!probablyMicrosoftPackage) { var gacLib = new DotnetLibrary { Culture = assemblyDescription.Culture, ProcessorArchitecture = assemblyDescription.ProcessorArchitecture, Name = name, Version = assemblyDescription.Version, Filepath = assemblyDescription.Path, }; FileInfo fi = new FileInfo(gacLib.Filepath); if (fi.Exists) { gacLib.Filename = fi.Name; FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(gacLib.Filepath); bool isDllFile = fvi.FileVersion != null; bool isMicrosoftCopyright = fvi.LegalCopyright != null && fvi.LegalCopyright.Contains("Microsoft Corporation"); if (isDllFile && !isMicrosoftCopyright) { gacLib.FileDescription = fvi.FileDescription; gacLib.Version = fvi.FileVersion; gacLib.ProductName = fvi.ProductName; gacLib.ProductVersion = fvi.ProductVersion; gacLib.Copyright = fvi.LegalCopyright; gacLib.Language = fvi.Language; gacLib.SHA1Hash = GetFileSHA1(gacLib.Filepath); gacLib.Md5Hash = GetFileMD5(gacLib.Filepath); gacList.Add(gacLib); } } } assemblyName = assemblyEnumerator.GetNextAssembly(); } } catch(Exception ex) { Trace.TraceWarning("Could not load DLL list from the GAC. Error: {0}", ex.ToString()); Console.Error.WriteLine("Could not load DLL list from the GAC."); return new List<DotnetLibrary>(); } return gacList; }