/// <summary> /// Loads projects. /// </summary> /// <param name="msbuildExeFileInfo">The <see cref="FileInfo" /> of MSBuild.exe.</param> /// <param name="projectCollection">The <see cref="ProjectCollection" /> to use when loading projects.</param> /// <param name="entryProjects">The <see cref="IEnumerable{String}" /> of entry projects.</param> /// <param name="globalProperties">The <see cref="IDictionary{String,String}" /> of global properties to use.</param> /// <param name="logger">A <see cref="ISlnGenLogger" /> to use as a logger.</param> /// <returns>A <see cref="Tuple{TimeSpan, Int32}" /> with the amount of time it took to load projects and the total number of projects that were loaded.</returns> public static (TimeSpan projectEvaluation, int projectCount) LoadProjects(FileInfo msbuildExeFileInfo, ProjectCollection projectCollection, IEnumerable <string> entryProjects, IDictionary <string, string> globalProperties, ISlnGenLogger logger) { if (logger.HasLoggedErrors) { return(TimeSpan.Zero, 0); } logger.LogMessageHigh("Loading project references..."); Stopwatch sw = Stopwatch.StartNew(); IProjectLoader projectLoader = Create(msbuildExeFileInfo, logger); try { projectLoader.LoadProjects(entryProjects, projectCollection, globalProperties); } catch (InvalidProjectFileException) { return(TimeSpan.Zero, 0); } catch (Exception e) { logger.LogError(e.ToString()); return(TimeSpan.Zero, 0); } sw.Stop(); logger.LogMessageNormal($"Loaded {projectCollection.LoadedProjects.Count:N0} project(s) in {sw.ElapsedMilliseconds:N0}ms"); return(sw.Elapsed, projectCollection.LoadedProjects.Count); }
private (TimeSpan projectEvaluation, int projectCount) LoadProjects(ProjectCollection projectCollection, ISlnGenLogger logger) { List <string> entryProjects = GetEntryProjectPaths(logger).ToList(); if (logger.HasLoggedErrors) { return(TimeSpan.Zero, 0); } logger.LogMessageHigh("Loading project references..."); Stopwatch sw = Stopwatch.StartNew(); IProjectLoader projectLoader = ProjectLoaderFactory.Create(_msbuildExePath, logger); IDictionary <string, string> globalProperties = GetGlobalProperties(); using (new MSBuildFeatureFlags { CacheFileEnumerations = true, LoadAllFilesAsReadOnly = true, MSBuildSkipEagerWildCardEvaluationRegexes = true, UseSimpleProjectRootElementCacheConcurrency = true, MSBuildExePath = _msbuildExePath.FullName, }) { try { projectLoader.LoadProjects(entryProjects, projectCollection, globalProperties); } catch (InvalidProjectFileException) { return(TimeSpan.Zero, 0); } catch (Exception e) { logger.LogError(e.ToString()); return(TimeSpan.Zero, 0); } } sw.Stop(); logger.LogMessageNormal($"Loaded {projectCollection.LoadedProjects.Count:N0} project(s) in {sw.ElapsedMilliseconds:N0}ms"); return(sw.Elapsed, projectCollection.LoadedProjects.Count); }