private void EvalCodeCover(string reportFile) { if (File.Exists(reportFile) == false) { _context.ConsoleWrite(reportFile + " NOT FOUND!"); return; } List <string> asmblyNames = SlnFileHelper.GetAssemblyNames(_slnFilePath); ReportResult reportResult = XmlHelper.XmlDeserializeFromFile <ReportResult>(reportFile); if (reportResult.Assemblies != null) { foreach (var a in reportResult.Assemblies) { if (a.Name.EndsWith(".UnitTest", StringComparison.OrdinalIgnoreCase)) { continue; } // 只计算解决方案中包含的项目 if (asmblyNames.FirstOrDefault(x => x.Equals(a.Name, StringComparison.OrdinalIgnoreCase)) == null) { continue; } _codeCoverResults.Add(new UnitTestResult { ProjectName = a.Name, Total = a.TotalStatements, Passed = a.CoveredStatements }); } } }
private List <Assembly> LoadAssemblies(AssemblyScanOption option) { List <string> asmNames = SlnFileHelper.GetAssemblyNames(option.Sln); string[] files = Directory.GetFiles(option.Bin, "*.dll", SearchOption.TopDirectoryOnly); List <Assembly> list = new List <Assembly>(); foreach (string file in files) { string filename = Path.GetFileNameWithoutExtension(file); if (asmNames.FindIndex(x => x.EqualsIgnoreCase(filename)) < 0) { continue; } // 过滤程序集,加快速度 //if( filename.StartsWith("MySoft", StringComparison.OrdinalIgnoreCase) == false ) // continue; // 忽略网站项目 if (filename.IndexOf("WebApplication", StringComparison.OrdinalIgnoreCase) > 0) { continue; } if (filename.IndexOf("WebSite", StringComparison.OrdinalIgnoreCase) > 0) { continue; } // 忽略测试项目的程序集 if (filename.IndexOf("Test", StringComparison.OrdinalIgnoreCase) > 0) { continue; } try { Assembly assembly = Assembly.LoadFrom(file); if (assembly != null) { list.Add(assembly); } } catch (Exception ex) { _invaidAssemblyList.Add(new KeyValuePair <string, Exception>(file, ex)); } } return(list); }