Esempio n. 1
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));
        }