Ejemplo n.º 1
0
        private async Task <bool> PerformNewBuildAsync(string projectPath, BuildInfo buildInfo)
        {
            // Switch to the UI thread and request the build
            var didStartBuild = await ThreadHelper.JoinableTaskFactory.RunAsync(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                var hr = _vsSolution.GetProjectOfUniqueName(projectPath, out var hierarchy);
                if (hr != VSConstants.S_OK)
                {
                    return(false);
                }

                hr = _vsBuildManager.StartSimpleUpdateProjectConfiguration(
                    hierarchy,
                    /* not used */ null,
                    /* not used */ null,
                    (uint)VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD,
                    /* other flags */ 0,
                    /* suppress dialogs */ 1);
                if (hr != VSConstants.S_OK)
                {
                    return(false);
                }

                return(true);
            });
        /// <summary>
        /// Builds the specified project.
        /// </summary>
        public async Task <bool> BuildProjectAsync(SolutionItem project, BuildAction action = BuildAction.Build)
        {
            if (project?.Type != SolutionItemType.Project && project?.Type != SolutionItemType.VirtualProject)
            {
                return(false);
            }

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsSolutionBuildManager svc = await VS.Services.GetSolutionBuildManagerAsync();

            uint buildFlags = (uint)GetBuildFlags(action);

            project.GetItemInfo(out IVsHierarchy hierarchy, out _, out _);

            BuildObserver observer = new(hierarchy);

            ErrorHandler.ThrowOnFailure(svc.AdviseUpdateSolutionEvents(observer, out uint cookie));

            try
            {
                ErrorHandler.ThrowOnFailure(svc.StartSimpleUpdateProjectConfiguration(hierarchy, null, null, buildFlags, 0, 0));
                return(await observer.Result);
            }
            finally
            {
                svc.UnadviseUpdateSolutionEvents(cookie);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds the solution or project if one is specified.
        /// </summary>
        public async Task <bool> BuildProjectAsync(SolutionItem project, BuildAction action = BuildAction.Build)
        {
            if (project?.Type != SolutionItemType.Project && project?.Type != SolutionItemType.VirtualProject)
            {
                return(false);
            }

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsSolutionBuildManager svc = await VS.Services.GetSolutionBuildManagerAsync();

            uint buildFlags = (uint)GetBuildFlags(action);

            project.GetItemInfo(out IVsHierarchy hierarchy, out _, out _);
            return(svc.StartSimpleUpdateProjectConfiguration(hierarchy, null, null, buildFlags, 0, 0) == VSConstants.S_OK);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Starts the specified build operation on the project for the currently selected project configuration.
        /// </summary>
        /// <param name="operation">The operation to perform.</param>
        public void StartBuild(BuildOperation operation)
        {
            Tracer.VerifyEnumArgument((int)operation, "operation", typeof(BuildOperation));

            // We have to verify that the environment is not busy right now
            if (Package.Instance.Context.IsSolutionBuilding)
            {
                Tracer.WriteLineVerbose(classType, "StartBuild", "The build manager is busy right now.");
                return;
            }

            // Get the build manager from VS
            IVsSolutionBuildManager solutionBuildMgr = this.ServiceProvider.GetServiceOrThrow(typeof(SVsSolutionBuildManager), typeof(IVsSolutionBuildManager), classType, "StartBuild") as IVsSolutionBuildManager;

            // Convert the enum to one of the VS flags
            VSSOLNBUILDUPDATEFLAGS flags = VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_NONE;

            switch (operation)
            {
            case BuildOperation.Clean:
                flags |= VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_CLEAN;
                break;

            case BuildOperation.Build:
                flags |= VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD;
                break;

            case BuildOperation.Rebuild:
                flags |= VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_CLEAN | VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD;
                break;

            default:
                Tracer.Fail("Unknown BuildOperation '{0}'", operation.ToString());
                return;
            }


            NativeMethods.ThrowOnFailure(solutionBuildMgr.StartSimpleUpdateProjectConfiguration((IVsHierarchy)this, null, null, (uint)flags, 0, 0));
        }