public void WhenAddingInterceptor_ThenCanInterceptIdeOperation() { this.OpenSolution("SampleSolution\\SampleSolution.sln"); var interceptor = new Mock <ICommandInterceptor>(); var commands = this.ServiceLocator.GetInstance <ICommandManager>(); commands.AddInterceptor(interceptor.Object, new CommandInterceptorAttribute( Constants.PackageGuid, "{5efc7975-14bc-11cf-9b2b-00aa00573819}", 0x372)); var mre = new ManualResetEventSlim(); var events = this.Dte.Events.BuildEvents; EnvDTE._dispBuildEvents_OnBuildDoneEventHandler done = (scope, action) => mre.Set(); events.OnBuildDone += done; this.Dte.ExecuteCommand("Build.BuildSolution"); mre.Wait(); Assert.True(BuildCommandInterceptor.BeforeExecuteCalled); Assert.True(BuildCommandInterceptor.AfterExecuteCalled); interceptor.Verify(x => x.BeforeExecute()); interceptor.Verify(x => x.AfterExecute()); }
/// <summary> /// Starts a build of the solution. /// </summary> public static Task <bool> Build(this ISolutionNode solution) { var sln = solution.As <EnvDTE.Solution>(); if (sln == null) { throw new ArgumentException(Strings.ISolutionNodeExtensions.BuildNotSupported); } return(System.Threading.Tasks.Task.Factory.StartNew <bool>(() => { var mre = new ManualResetEventSlim(); var events = sln.DTE.Events.BuildEvents; EnvDTE._dispBuildEvents_OnBuildDoneEventHandler done = (scope, action) => mre.Set(); events.OnBuildDone += done; try { // Let build run async. sln.SolutionBuild.Build(false); // Wait until it's done. mre.Wait(); // LastBuildInfo == # of projects that failed to build. return sln.SolutionBuild.LastBuildInfo == 0; } catch (Exception ex) { tracer.Error(ex, Strings.ISolutionNodeExtensions.BuildException); return false; } finally { // Cleanup handler. events.OnBuildDone -= done; } }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default)); }