Example #1
0
		public async Task BuildWithCustomProps ()
		{
			string projFile = Util.GetSampleProject ("msbuild-tests", "project-with-custom-build-target.csproj");
			var p = (Project)await Services.ProjectService.ReadSolutionItem (Util.GetMonitor (), projFile);

			var ctx = new ProjectOperationContext ();
			ctx.GlobalProperties.SetValue ("TestProp", "foo");
			var res = await p.Build (Util.GetMonitor (), p.Configurations [0].Selector, ctx);

			Assert.AreEqual (1, res.Errors.Count);
			Assert.AreEqual ("Something failed: foo", res.Errors [0].ErrorText);

			await p.Clean (Util.GetMonitor (), p.Configurations [0].Selector);
			res = await p.Build (Util.GetMonitor (), p.Configurations [0].Selector, true);

			// Check that the global property is reset
			Assert.AreEqual (1, res.Errors.Count);
			Assert.AreEqual ("Something failed: show", res.Errors [0].ErrorText);
		}
Example #2
0
		IAsyncOperation Build (IBuildTarget entry, bool skipPrebuildCheck, ProjectOperationContext context = null)
		{
			if (currentBuildOperation != null && !currentBuildOperation.IsCompleted) return currentBuildOperation;
			/*
			if (!errorPadInitialized) {
				try {
					Pad errorsPad = IdeApp.Workbench.GetPad<MonoDevelop.Ide.Gui.Pads.ErrorListPad> ();
					errorsPad.Window.PadHidden += delegate {
						content.IsOpenedAutomatically = false;
					};
					
					Pad monitorPad = IdeApp.Workbench.Pads.FirstOrDefault (pad => pad.Content == ((OutputProgressMonitor)((AggregatedProgressMonitor)monitor).MasterMonitor).OutputPad);
					monitorPad.Window.PadHidden += delegate {
						monitorPad.IsOpenedAutomatically = false;
					};
				} finally {
					errorPadInitialized = true;
				}
			}
			*/
			
			ITimeTracker tt = Counters.BuildItemTimer.BeginTiming ("Building " + entry.Name);
			try {
				IProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetBuildProgressMonitor ();
				BeginBuild (monitor, tt, false);
				DispatchService.ThreadDispatch (() => BuildSolutionItemAsync (entry, monitor, tt, skipPrebuildCheck, context));
				currentBuildOperation = monitor.AsyncOperation;
				currentBuildOperationOwner = entry;
				currentBuildOperation.Completed += delegate { currentBuildOperationOwner = null; };
			} catch {
				tt.End ();
				throw;
			}
			return currentBuildOperation;
		}
Example #3
0
		void BuildSolutionItemAsync (IBuildTarget entry, IProgressMonitor monitor, ITimeTracker tt, bool skipPrebuildCheck = false, ProjectOperationContext context = null)
		{
			BuildResult result = null;
			try {
				if (!skipPrebuildCheck) {
					tt.Trace ("Pre-build operations");
					result = DoBeforeCompileAction ();
				}

				//wait for any custom tools that were triggered by the save, since the build may depend on them
				MonoDevelop.Ide.CustomTools.CustomToolService.WaitForRunningTools (monitor);

				if (skipPrebuildCheck || result.ErrorCount == 0) {
					tt.Trace ("Building item");
					SolutionItem it = entry as SolutionItem;
					if (it != null)
						result = it.Build (monitor, IdeApp.Workspace.ActiveConfiguration, true, context);
					else if (entry is WorkspaceItem)
						result = ((WorkspaceItem)entry).Build (monitor, IdeApp.Workspace.ActiveConfiguration, context);
					else
						result = entry.RunTarget (monitor, ProjectService.BuildTarget, IdeApp.Workspace.ActiveConfiguration);
				}
			} catch (Exception ex) {
				monitor.ReportError (GettextCatalog.GetString ("Build failed."), ex);
				if (result == null)
					result = new BuildResult ();
				result.AddError ("Build failed. See the build log for details.");
				if (result.SourceTarget == null)
					result.SourceTarget = entry;
			} finally {
				tt.Trace ("Done building");
			}
			DispatchService.GuiDispatch (
				delegate {
					BuildDone (monitor, result, entry, tt);	// BuildDone disposes the monitor
			});
		}
Example #4
0
		public IAsyncOperation Rebuild (IBuildTarget entry, ProjectOperationContext context)
		{
			if (currentBuildOperation != null && !currentBuildOperation.IsCompleted) return currentBuildOperation;
			
			ITimeTracker tt = Counters.BuildItemTimer.BeginTiming ("Rebuilding " + entry.Name);
			try {
				IProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetRebuildProgressMonitor ();
				OnStartClean (monitor, tt);

				DispatchService.ThreadDispatch (delegate {
					CleanAsync (entry, monitor, tt, true);
					if (monitor.AsyncOperation.IsCompleted && !monitor.AsyncOperation.Success) {
						tt.End ();
						monitor.Dispose ();
						return;
					}
					if (StartBuild != null) {
						DispatchService.GuiSyncDispatch (() => BeginBuild (monitor, tt, true));
					}
					BuildSolutionItemAsync (entry, monitor, tt, context:context);
				}, null);
				currentBuildOperation = monitor.AsyncOperation;
				currentBuildOperationOwner = entry;
				currentBuildOperation.Completed += delegate { currentBuildOperationOwner = null; };
			} catch {
				tt.End ();
				throw;
			}
			return currentBuildOperation;
		}
Example #5
0
		public IAsyncOperation Build (IBuildTarget entry, ProjectOperationContext context)
		{
			return Build (entry, false, context);
		}
//		bool errorPadInitialized = false;

		public AsyncOperation<BuildResult> Build (Project project, CancellationToken? cancellationToken = null, ProjectOperationContext operationContext = null)
		{
			return Build (project, false, cancellationToken, operationContext);
		}
		public AsyncOperation<BuildResult> Rebuild (Project project, ProjectOperationContext operationContext = null)
		{
			return Rebuild ((IBuildTarget)project, operationContext);
		}
Example #8
0
		protected override void Run ()
		{
			var context = new ProjectOperationContext ();
			context.GlobalProperties.Add ("RunCodeAnalysisOnce", "true");
			IdeApp.ProjectOperations.Rebuild (IdeApp.ProjectOperations.CurrentSelectedProject, context);
		}
Example #9
0
 public BuildResult Build(IProgressMonitor monitor, ConfigurationSelector solutionConfiguration, bool buildReferences, ProjectOperationContext context)
 {
     try {
         System.Runtime.Remoting.Messaging.CallContext.SetData("MonoDevelop.Projects.ProjectOperationContext", context);
         return(Build(monitor, solutionConfiguration, buildReferences));
     } finally {
         System.Runtime.Remoting.Messaging.CallContext.SetData("MonoDevelop.Projects.ProjectOperationContext", null);
     }
 }
Example #10
0
 public BuildResult Build(IProgressMonitor monitor, string configuration, ProjectOperationContext context)
 {
     return(Build(monitor, (SolutionConfigurationSelector)configuration, context));
 }