public async Task <BuildResults> BuildAsync(IEnumerable <IProject> projects, BuildOptions options) { if (projects == null) { throw new ArgumentNullException("projects"); } if (options == null) { throw new ArgumentNullException("options"); } SD.MainThread.VerifyAccess(); if (guiBuildCancellation != null) { BuildResults results = new BuildResults(); SD.StatusBar.SetMessage(ResourceService.GetString("MainWindow.CompilerMessages.MSBuildAlreadyRunning")); BuildError error = new BuildError(null, ResourceService.GetString("MainWindow.CompilerMessages.MSBuildAlreadyRunning")); results.Add(error); TaskService.Add(new SDTask(error)); results.Result = BuildResultCode.MSBuildAlreadyRunning; return(results); } var projectsList = projects.ToList(); guiBuildCancellation = new CancellationTokenSource(); try { using (var progressMonitor = SD.StatusBar.CreateProgressMonitor(guiBuildCancellation.Token)) { if (BuildStarted != null) { BuildStarted(this, new BuildEventArgs(projectsList, options)); } var trackedFeature = SD.AnalyticsMonitor.TrackFeature("ICSharpCode.SharpDevelop.Project.BuildEngine.Build"); SD.StatusBar.SetMessage(StringParser.Parse("${res:MainWindow.CompilerMessages.BuildVerb}...")); IBuildable buildable; if (projectsList.Count == 1) { buildable = projectsList[0]; } else { buildable = new MultipleProjectBuildable(projectsList); } buildable = buildModifiedProjectsOnly.WrapBuildable(buildable, options.BuildDetection); var sink = new UIBuildFeedbackSink(SD.OutputPad.BuildCategory, SD.StatusBar); // Actually run the build: var results = await BuildEngine.BuildAsync(buildable, options, sink, progressMonitor); string message; if (results.Result == BuildResultCode.Cancelled) { message = "${res:MainWindow.CompilerMessages.BuildCancelled}"; } else { if (results.Result == BuildResultCode.Success) { message = "${res:MainWindow.CompilerMessages.BuildFinished}"; } else { message = "${res:MainWindow.CompilerMessages.BuildFailed}"; } if (results.ErrorCount > 0) { message += " " + results.ErrorCount + " error(s)"; } if (results.WarningCount > 0) { message += " " + results.WarningCount + " warning(s)"; } } SD.StatusBar.SetMessage(message); trackedFeature.EndTracking(); if (BuildFinished != null) { BuildFinished(this, new BuildEventArgs(projectsList, options, results)); } return(results); } } finally { guiBuildCancellation = null; } }
public async Task<BuildResults> BuildAsync(IEnumerable<IProject> projects, BuildOptions options) { if (projects == null) throw new ArgumentNullException("projects"); if (options == null) throw new ArgumentNullException("options"); SD.MainThread.VerifyAccess(); if (guiBuildCancellation != null) { BuildResults results = new BuildResults(); SD.StatusBar.SetMessage(ResourceService.GetString("MainWindow.CompilerMessages.MSBuildAlreadyRunning")); BuildError error = new BuildError(null, ResourceService.GetString("MainWindow.CompilerMessages.MSBuildAlreadyRunning")); results.Add(error); TaskService.Add(new SDTask(error)); results.Result = BuildResultCode.MSBuildAlreadyRunning; return results; } var projectsList = projects.ToList(); guiBuildCancellation = new CancellationTokenSource(); try { using (var progressMonitor = SD.StatusBar.CreateProgressMonitor(guiBuildCancellation.Token)) { if (BuildStarted != null) BuildStarted(this, new BuildEventArgs(projectsList, options)); var trackedFeature = SD.AnalyticsMonitor.TrackFeature("ICSharpCode.SharpDevelop.Project.BuildEngine.Build"); SD.StatusBar.SetMessage(StringParser.Parse("${res:MainWindow.CompilerMessages.BuildVerb}...")); IBuildable buildable; if (projectsList.Count == 1) buildable = projectsList[0]; else buildable = new MultipleProjectBuildable(projectsList); buildable = buildModifiedProjectsOnly.WrapBuildable(buildable, options.BuildDetection); var sink = new UIBuildFeedbackSink(SD.OutputPad.BuildCategory, SD.StatusBar); // Actually run the build: var results = await BuildEngine.BuildAsync(buildable, options, sink, progressMonitor); string message; if (results.Result == BuildResultCode.Cancelled) { message = "${res:MainWindow.CompilerMessages.BuildCancelled}"; } else { if (results.Result == BuildResultCode.Success) message = "${res:MainWindow.CompilerMessages.BuildFinished}"; else message = "${res:MainWindow.CompilerMessages.BuildFailed}"; if (results.ErrorCount > 0) message += " " + results.ErrorCount + " error(s)"; if (results.WarningCount > 0) message += " " + results.WarningCount + " warning(s)"; } SD.StatusBar.SetMessage(message); trackedFeature.EndTracking(); if (BuildFinished != null) BuildFinished(this, new BuildEventArgs(projectsList, options, results)); return results; } } finally { guiBuildCancellation = null; } }