Esempio n. 1
0
        /// <summary>
        /// Ensures the project is up to date.  Returns true if the project is up to date
        /// or is successfully built, false if it's not up to date.
        /// </summary>
        private async Task <bool> EnsureProjectUpToDate(EnvDTE.Project projectToProfile)
        {
            var          guid     = Guid.Parse((string)projectToProfile.Properties.Item("Guid").Value);
            var          solution = (IVsSolution)GetService(typeof(SVsSolution));
            IVsHierarchy hierarchy;

            if (ErrorHandler.Succeeded(solution.GetProjectOfGuid(ref guid, out hierarchy)))
            {
                var buildMan = (IVsSolutionBuildManager)GetService(typeof(SVsSolutionBuildManager));
                if (buildMan != null)
                {
                    if (((IVsSolutionBuildManager3)buildMan).AreProjectsUpToDate(0) == VSConstants.S_OK)
                    {
                        // projects are up to date, no need to build.
                        return(true);
                    }

                    uint updateCookie = VSConstants.VSCOOKIE_NIL;
                    var  updateEvents = new UpdateSolutionEvents();
                    try
                    {
                        if (ErrorHandler.Succeeded(buildMan.AdviseUpdateSolutionEvents(updateEvents, out updateCookie)))
                        {
                            int hr;
                            if (ErrorHandler.Succeeded(
                                    hr = buildMan.StartSimpleUpdateProjectConfiguration(
                                        hierarchy,
                                        null,
                                        null,
                                        (uint)(VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD),
                                        0,
                                        0
                                        )))
                            {
                                return(await updateEvents.Task);
                            }
                        }
                    }
                    finally
                    {
                        if (updateCookie != VSConstants.VSCOOKIE_NIL)
                        {
                            buildMan.UnadviseUpdateSolutionEvents(updateCookie);
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 2
0
        private void WaitForBuildToFinish(EnvDTE.OutputWindowPane buildOutputWindowPane)
        {
            var buildManager = GetGlobalService <SVsSolutionBuildManager, IVsSolutionBuildManager2>();

            using (var semaphore = new SemaphoreSlim(1))
                using (var solutionEvents = new UpdateSolutionEvents(buildManager))
                {
                    semaphore.Wait();
                    UpdateSolutionEvents.UpdateSolutionDoneEvent @event = (bool succeeded, bool modified, bool canceled) => semaphore.Release();
                    solutionEvents.OnUpdateSolutionDone += @event;
                    try
                    {
                        semaphore.Wait();
                    }
                    finally
                    {
                        solutionEvents.OnUpdateSolutionDone -= @event;
                    }
                }
        }
Esempio n. 3
0
        public void WaitForBuildToFinish()
        {
            var buildManager = GetGlobalService <SVsSolutionBuildManager, IVsSolutionBuildManager2>();

            using (var semaphore = new SemaphoreSlim(1))
                using (var solutionEvents = new UpdateSolutionEvents(buildManager))
                {
                    semaphore.Wait();
                    void @event(bool succeeded, bool modified, bool canceled) => semaphore.Release();

                    solutionEvents.OnUpdateSolutionDone += @event;
                    try
                    {
                        semaphore.Wait(Helper.HangMitigatingTimeout);
                    }
                    finally
                    {
                        solutionEvents.OnUpdateSolutionDone -= @event;
                    }
                }
        }
        /// <summary>
        /// Ensures the project is up to date.  Returns true if the project is up to date
        /// or is successfully built, false if it's not up to date.
        /// </summary>
        private async Task<bool> EnsureProjectUpToDate(EnvDTE.Project projectToProfile) {
            var guid = Guid.Parse((string)projectToProfile.Properties.Item("Guid").Value);
            var solution = (IVsSolution)GetService(typeof(SVsSolution));
            IVsHierarchy hierarchy;
            if (ErrorHandler.Succeeded(solution.GetProjectOfGuid(ref guid, out hierarchy))) {
                var buildMan = (IVsSolutionBuildManager)GetService(typeof(SVsSolutionBuildManager));
                if (buildMan != null) {
                    if (((IVsSolutionBuildManager3)buildMan).AreProjectsUpToDate(0) == VSConstants.S_OK) {
                        // projects are up to date, no need to build.
                        return true;
                    }

                    uint updateCookie = VSConstants.VSCOOKIE_NIL;
                    var updateEvents = new UpdateSolutionEvents();
                    try {
                        if (ErrorHandler.Succeeded(buildMan.AdviseUpdateSolutionEvents(updateEvents, out updateCookie))) {
                            int hr;
                            if (ErrorHandler.Succeeded(
                                hr = buildMan.StartSimpleUpdateProjectConfiguration(
                                hierarchy,
                                null,
                                null,
                                (uint)(VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD),
                                0,
                                0
                            ))) {
                                return await updateEvents.Task;
                            }
                        }
                    } finally {
                        if (updateCookie != VSConstants.VSCOOKIE_NIL) {
                            buildMan.UnadviseUpdateSolutionEvents(updateCookie);
                        }
                    }
                }
            }

            return true;
        }