private static Project LoadProject(string projectFile, string targetFramework) { var sw = Stopwatch.StartNew(); BinaryLogger logger = null; try { var properties = new Dictionary <string, string>() { ["Configuration"] = "Debug", }; if (!string.IsNullOrEmpty(targetFramework)) { properties["TargetFramework"] = targetFramework; } var xmlReader = XmlReader.Create(projectFile); var collection = new ProjectCollection(); // Change this logger details to troubleshoot project loading details. collection.RegisterLogger(new Microsoft.Build.Logging.ConsoleLogger() { Verbosity = LoggerVerbosity.Minimal }); collection.RegisterLogger(logger = new BinaryLogger() { Parameters = @"test.binlog;ProjectImports=ZipFile", Verbosity = LoggerVerbosity.Diagnostic }); collection.OnlyLogCriticalEvents = false; var xml = Microsoft.Build.Construction.ProjectRootElement.Create(xmlReader, collection); // When constructing a project from an XmlReader, MSBuild cannot determine the project file path. Setting the xml.FullPath = Path.GetFullPath(projectFile); return(new Project( xml, properties, toolsVersion: null, projectCollection: collection )); } finally { logger?.Shutdown(); Console.WriteLine($"[{sw.Elapsed}] Loaded {projectFile} for {targetFramework}"); } }
public override void Shutdown() { _binaryLogger.Shutdown(); if (_build != null) { _build.SetLogPath(GetLogPath(_build)); Copy(_logPath, _build.LogPath); DataSource.NotifyChange(); } else { // Never got project information so just delete the log. File.Delete(_logPath); } }
public Task Save(string filePath) { return(Task.Run(() => { var eventsSource = new BuildOutputEventsSource(); var logger = new BinaryLogger { CollectProjectImports = BinaryLogger.ProjectImportsCollectionMode.None, Parameters = filePath, Verbosity = LoggerVerbosity.Diagnostic }; try { logger.Initialize(eventsSource); foreach (var proj in projects) { switch (proj) { case MSBuildOutputProcessor msbop: eventsSource.ProcessFile(proj.FileName); break; case BuildOutputProcessor bop: // FIXME break; default: continue; } } } catch (Exception ex) { LoggingService.LogError($"Can't write to {filePath}: {ex.Message})"); } finally { logger.Shutdown(); } })); }