public static Models.Assembly ProcessSingleAssembly(string filePath) { var output = new Models.Assembly(); AppDomainSetup appSetup = new AppDomainSetup(); appSetup.ApplicationBase = Environment.CurrentDirectory; //@"C:\Projects\Store Trunk\trunk\PackageVerification\PackageVerification\PackageVerification.AssemblyScanner\bin\Debug"; Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; Evidence evidence = new Evidence(baseEvidence); var sandbox = AppDomain.CreateDomain("Sandbox", evidence, appSetup); try { sandbox.SetData("filePath", filePath); sandbox.DoCallBack(MyCallBack); var imageRuntimeVersion = (String)sandbox.GetData("imageRuntimeVersion"); var assemblyName = (String)sandbox.GetData("assemblyName"); var referencedAssemblies = (AssemblyName[])sandbox.GetData("referencedAssemblies"); //populate the base assembly info output = ProcessAssemblyInfo(output, assemblyName); //Let's get the base framework info foreach (var frameworkInfo in DotNetVersions.FrameworkList()) { if (imageRuntimeVersion == frameworkInfo.CLRVersion) { output.Framework = frameworkInfo; break; } } //populate the referenced assemblies list. foreach (var an in referencedAssemblies) { var assembly = new Models.Assembly(); output.References.Add(ProcessAssemblyInfo(assembly, an.FullName)); } } finally { AppDomain.Unload(sandbox); } return(output); }
private static Models.Assembly ProcessAssemblyInfo(Models.Assembly input, string assemblyInfo) { var output = input; var parts = assemblyInfo.Split(',').Select(x => x.Trim()).ToList(); var name = ""; var version = ""; var culture = ""; var token = ""; foreach (var part in parts) { if (part.StartsWith("Version=")) { version = part.Substring(8); } else if (part.StartsWith("Culture=")) { culture = part.Substring(8); } else if (part.StartsWith("PublicKeyToken=")) { token = part.Substring(15); } else { name = part; } } output.Name = name; output.Version = version; output.Culture = culture; output.PublicKeyToken = token; return(output); }