Beispiel #1
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                tools.Release();
                tools = null;

                sharedTaskManagers.Clear();
                sharedTaskManagers = null;

                if (buildManager != null)
                {
                    buildManager.UnadviseUpdateSolutionEvents(buildManagerCookie);
                    buildManager = null;
                }

                if (solution != null)
                {
                    solution.UnadviseSolutionEvents(solutionEventsCookie);
                    solution = null;
                }

                taskListMenu.Release();
                taskListMenu = null;
                Common.Release();
                GC.SuppressFinalize(this);
            }
            base.Dispose(disposing);
        }
Beispiel #2
0
        /// <inheritdoc/>
        protected override void Dispose(bool disposing)
        {
            foreach (string file in this.TempFilesCreated)
            {
                try
                {
                    File.Delete(file);
                }
                catch (Exception ex)
                {
                    this.LogMessageWriteLineFormat(
                        "There was an error deleting a temp file [{0}], error: [{1}]",
                        file,
                        ex.Message);
                }
            }

            if (this.solutionUpdateCookie > 0)
            {
                IVsSolutionBuildManager solutionBuildManager = this.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager;
                solutionBuildManager.UnadviseUpdateSolutionEvents(this.solutionUpdateCookie);
            }

            base.Dispose(disposing);
        }
        internal BuildEvents()
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            IVsSolutionBuildManager svc = VS.GetRequiredService <SVsSolutionBuildManager, IVsSolutionBuildManager>();

            svc !.AdviseUpdateSolutionEvents(this, out _);
        }
        private EnvDTE.Properties TryGetStartupProjectProperties()
        {
            try
            {
                IVsSolutionBuildManager solutionBuildManager = GetGlobalService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager;
                if (solutionBuildManager == null)
                {
                    return(null);
                }

                IVsHierarchy startupProject;
                if (ErrorHandler.Failed(solutionBuildManager.get_StartupProject(out startupProject)) || startupProject == null)
                {
                    return(null);
                }

                EnvDTE.Properties properties = TryGetDtePropertiesFromHierarchy(startupProject);
                return(properties);
            }
            catch (Exception ex)
            {
                if (ErrorHandler.IsCriticalException(ex))
                {
                    throw;
                }

                return(null);
            }
        }
Beispiel #5
0
        public void Dispose()
        {
            // Unregister from receiving solution events
            if (VSConstants.VSCOOKIE_NIL != _vsSolutionEventsCookie)
            {
                IVsSolution sol = (IVsSolution)_sccProvider.GetService(typeof(SVsSolution));
                sol.UnadviseSolutionEvents(_vsSolutionEventsCookie);
                _vsSolutionEventsCookie = VSConstants.VSCOOKIE_NIL;
            }

            // Unregister from receiving project documents
            if (VSConstants.VSCOOKIE_NIL != _tpdTrackProjectDocumentsCookie)
            {
                IVsTrackProjectDocuments2 tpdService = (IVsTrackProjectDocuments2)_sccProvider.GetService(typeof(SVsTrackProjectDocuments));
                tpdService.UnadviseTrackProjectDocumentsEvents(_tpdTrackProjectDocumentsCookie);
                _tpdTrackProjectDocumentsCookie = VSConstants.VSCOOKIE_NIL;
            }

            // Unregister from storrage events
            _sccStatusTracker.HGStatusChanged -= new HGLib.HGStatusChangedEvent(SetNodesGlyphsDirty);

            IVsSolutionBuildManager buildManagerService = _sccProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager;

            buildManagerService.UnadviseUpdateSolutionEvents(_dwBuildManagerCooky);
        }
Beispiel #6
0
        //Code from StaticAnalysisPolicy class in the StanPolicy.dll file
        private bool ProjectUptoDate(Project project, List <PolicyFailure> failuresList)
        {
            IVsBuildableProjectCfg cfg1;
            IVsHierarchy           hierarchy1 = GetVsProjectFromDTE(project);

            IVsProjectCfg2[]        cfgArray1          = new IVsProjectCfg2[1];
            IVsSolutionBuildManager m_currBuildManager = PendingCheckin.GetService(typeof(IVsSolutionBuildManager)) as IVsSolutionBuildManager;

            m_currBuildManager.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy1, cfgArray1);
            if (cfgArray1[0] == null)
            {
                return(false);
            }
            cfgArray1[0].get_BuildableProjectCfg(out cfg1);
            if (cfg1 == null)
            {
                return(false);
            }
            int[] numArray1 = new int[1];
            int[] numArray2 = new int[1];
            int   num1      = cfg1.QueryStartUpToDateCheck(1, numArray1, numArray2);

            if ((numArray1[0] != 0) && !ErrorHandler.Failed(num1))
            {
                //http://msdn2.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivsbuildableprojectcfg.startuptodatecheck(VS.80).aspx
                num1 = cfg1.StartUpToDateCheck(null, 1);
                if (ErrorHandler.Failed(num1))
                {
                    string text1 = String.Format(errMessage, project.Name);
                    failuresList.Add(new PolicyFailure(text1, this));
                    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);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Checks if the project build is up to date.
        /// </summary>
        public async Task <bool> ProjectIsUpToDateAsync(SolutionItem project)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

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

            IVsProjectCfg2[] projectConfig = new IVsProjectCfg2[1];

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

            if (ErrorHandler.Succeeded(svc.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy, projectConfig)))
            {
                int[] supported = new int[1];
                int[] ready     = new int[1];

                if (ErrorHandler.Succeeded(projectConfig[0].get_BuildableProjectCfg(out IVsBuildableProjectCfg buildableProjectConfig)) &&
                    ErrorHandler.Succeeded(buildableProjectConfig.QueryStartUpToDateCheck(0, supported, ready)) &&
                    supported[0] == 1)
                {
                    return(ErrorHandler.Succeeded(buildableProjectConfig.StartUpToDateCheck(null, (uint)VsUpToDateCheckFlags.VSUTDCF_DTEEONLY)));
                }
            }

            return(false);
        }
Beispiel #9
0
        /// <summary>
        /// Build active project as if project's DynVarOption property was set to EverythingDynamic.
        /// For this, following steps are taken:
        /// -Set active project's DynVarOption property to EverythingDynamic,
        /// -Build the project
        /// -Restore old property value.
        /// Uses a <see cref="SolutionBuildListener"/> object for the property changes to take effect.
        /// </summary>
        /// <param name="sender">Not used.</param>
        /// <param name="e">Not used.</param>
        public void BuildEverythingDynamicCommand(object sender, EventArgs e)
        {
            IVsSolutionBuildManager buildManager =
                Package.GetGlobalService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager;

            if (buildManager != null)
            {
                string dynOptionKey      = PropertyTag.DynVarOption.ToString();
                string everythingDynamic = DynVarOption.EverythingDynamic.ToString();

                ProjectConfiguration.Instance.SetProperty(dynOptionKey, everythingDynamic);

                //SolutionBuildListener object will change project's DynVarOption property value before and after the build
                //(Constructor handles Advising, events handle Unadvising)
                //new SolutionBuildListener(buildManager, dynOptionKey, everythingDynamic);



                var DTEObj = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
                var sb     = (DTEObj.Solution.SolutionBuild as SolutionBuild);
                sb.Build();

                //check the projectIcon
                ProjectConfiguration.Instance.GetActiveProjectNode().checkProjectIcon();

                SourceHelper.refreshHighlighting();
            }
        }
Beispiel #10
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            this.LogMessageWriteLineFormat("SlowCheetah initalizing");

            // Initialization logic
            this.LogMessageWriteLineFormat(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));

            this.errorListProvider = new ErrorListProvider(this);
            IVsSolutionBuildManager solutionBuildManager = this.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager;

            solutionBuildManager.AdviseUpdateSolutionEvents(this, out this.solutionUpdateCookie);

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = this.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (mcs != null)
            {
                // create the command for the "Add Transform" query status menu item
                CommandID      menuContextCommandID = new CommandID(Guids.GuidSlowCheetahCmdSet, (int)PkgCmdID.CmdIdAddTransform);
                OleMenuCommand menuCommand          = new OleMenuCommand(this.OnAddTransformCommand, this.OnChangeAddTransformMenu, this.OnBeforeQueryStatusAddTransformCommand, menuContextCommandID);
                mcs.AddCommand(menuCommand);

                // create the command for the Preview Transform menu item
                menuContextCommandID = new CommandID(Guids.GuidSlowCheetahCmdSet, (int)PkgCmdID.CmdIdPreviewTransform);
                menuCommand          = new OleMenuCommand(this.OnPreviewTransformCommand, this.OnChangePreviewTransformMenu, this.OnBeforeQueryStatusPreviewTransformCommand, menuContextCommandID);
                mcs.AddCommand(menuCommand);
            }
        }
Beispiel #11
0
        protected override void Initialize()
        {
            base.Initialize();

            // Initialize common functionality
            Common.Initialize(this);
            taskListMenu = new RootMenu();

            // Initialize fields
            tools = new Tools();
            sharedTaskManagers = new List <TaskManager>();

            // Attach to solution events
            solution = GetService(typeof(SVsSolution)) as IVsSolution;
            // if (solution == null) throw new NullReferenceException();
            solution.AdviseSolutionEvents(this as IVsSolutionEvents, out solutionEventsCookie);

            // Attach to build events
            buildManager = GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager;
            // if (buildManager == null) throw new NullReferenceException();
            buildManager.AdviseUpdateSolutionEvents(this, out buildManagerCookie);

            // Add a TaskManagerFactory service
            (this as System.ComponentModel.Design.IServiceContainer).AddService(typeof(ITaskManagerFactory), this, true);
        }
 internal VsResetInteractive(DTE dte, IComponentModel componentModel, IVsMonitorSelection monitorSelection, IVsSolutionBuildManager buildManager, Func<string, string> createReference, Func<string, string> createImport)
     : base(createReference, createImport)
 {
     _dte = dte;
     _componentModel = componentModel;
     _monitorSelection = monitorSelection;
     _buildManager = buildManager;
 }
Beispiel #13
0
 internal VsResetInteractive(DTE dte, IComponentModel componentModel, IVsMonitorSelection monitorSelection, IVsSolutionBuildManager buildManager, Func <string, string> createReference, Func <string, string> createImport)
     : base(createReference, createImport)
 {
     _dte              = dte;
     _componentModel   = componentModel;
     _monitorSelection = monitorSelection;
     _buildManager     = buildManager;
 }
Beispiel #14
0
 /// <summary>
 /// Returns the build manager of the solution.
 /// </summary>
 /// <returns></returns>
 public IVsSolutionBuildManager GetVsSolutionBuildManager()
 {
     if (_vsSolutionBuildManager == null)
     {
         _vsSolutionBuildManager = PackageHelper.GetService <IVsSolutionBuildManager>(typeof(SVsSolutionBuildManager));
     }
     return(_vsSolutionBuildManager);
 }
Beispiel #15
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="buildManager">IVsSolutionBuildManager service (for registering this object).</param>
        /// <param name="propertyKey">Key of the property to be modified during build.</param>
        /// <param name="newValue">Value during build for the property to be modified.</param>
        public SolutionBuildListener(IVsSolutionBuildManager buildManager, string propertyKey, string newValue)
        {
            this.buildManager = buildManager;
            this.propertyKey  = propertyKey;
            this.newValue     = newValue;
            this.oldValue     = ProjectConfiguration.Instance.GetProperty(propertyKey);

            buildManager.AdviseUpdateSolutionEvents(this, out cookie);
        }
Beispiel #16
0
        private static async Task AdviseSolutionEventsAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            _solutionBuildManager = ServiceLocator.GetService <SVsSolutionBuildManager, IVsSolutionBuildManager>();
            Assumes.Present(_solutionBuildManager);

            _solutionBuildManager.AdviseUpdateSolutionEvents(_solutionEventHandler, out _updateSolutionEventsCookie);
        }
        public VsUpdateSolutionEvents(
            IVsSolutionBuildManager buildManager,
            TaskCompletionSource <bool> taskSource)
        {
            _taskSource   = taskSource;
            _buildManager = buildManager;

            Marshal.ThrowExceptionForHR(
                buildManager.AdviseUpdateSolutionEvents(this, out _cookie));
        }
Beispiel #18
0
        /// <summary>
        /// Builds the solution or project if one is specified.
        /// </summary>
        public async Task <bool> BuildSolutionAsync(BuildAction action = BuildAction.Build)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

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

            uint buildFlags = (uint)GetBuildFlags(action);

            return(svc.StartSimpleUpdateSolutionConfiguration(buildFlags, 0, 0) == VSConstants.S_OK);
        }
Beispiel #19
0
        public UpdateSolutionEvents(Commands commands)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            _commands = commands;

            // Subscribe to events
            IVsSolutionBuildManager buildManager = (IVsSolutionBuildManager)Package.GetGlobalService(typeof(SVsSolutionBuildManager)) ?? throw new ArgumentNullException(nameof(buildManager));

            buildManager.AdviseUpdateSolutionEvents(this, out _cookie);
        }
        public VsUpdateSolutionEvents(
            IVsSolutionBuildManager buildManager,
            TaskCompletionSource<bool> taskSource)
        {
            _taskSource = taskSource;
            _buildManager = buildManager;

            Marshal.ThrowExceptionForHR(
                buildManager.AdviseUpdateSolutionEvents(this, out _cookie));
        }
        private static IVsHierarchy GetStartupProjectHierarchy()
        {
            IVsSolutionBuildManager build = DockableCLArgsPackage.GetGlobalService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager;
            IVsHierarchy            hierarchy;

            if (ErrorHandler.Failed(build.get_StartupProject(out hierarchy)))
            {
                return(null);
            }

            return(hierarchy);
        }
Beispiel #22
0
        /// <summary>
        /// When building a wixproj in VS, the configuration of referenced projects cannot be determined
        /// by MSBuild or from within an MSBuild task. So we'll get them from the VS project system here.
        /// </summary>
        /// <param name="project">The project where the properties are being defined; also the project
        /// whose references are being examined.</param>
        internal static void DefineProjectReferenceConfigurations(WixProjectNode project)
        {
            StringBuilder configList = new StringBuilder();

            IVsSolutionBuildManager solutionBuildManager =
                WixHelperMethods.GetService <IVsSolutionBuildManager, SVsSolutionBuildManager>(project.Site);

            List <WixProjectReferenceNode> referenceNodes = new List <WixProjectReferenceNode>();

            project.FindNodesOfType(referenceNodes);

            foreach (WixProjectReferenceNode referenceNode in referenceNodes)
            {
                IVsHierarchy hierarchy = VsShellUtilities.GetHierarchy(referenceNode.ProjectMgr.Site, referenceNode.ReferencedProjectGuid);

                string          configuration   = null;
                IVsProjectCfg2  projectCfg2     = null;
                IVsProjectCfg[] projectCfgArray = new IVsProjectCfg[1];

                int hr = solutionBuildManager.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy, projectCfgArray);
                ErrorHandler.ThrowOnFailure(hr);

                projectCfg2 = projectCfgArray[0] as IVsProjectCfg2;

                if (projectCfg2 != null)
                {
                    hr = projectCfg2.get_DisplayName(out configuration);
                    if (hr != 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                }

                if (configuration != null)
                {
                    if (configList.Length > 0)
                    {
                        configList.Append(';');
                    }

                    configList.Append(referenceNode.ReferencedProjectName);
                    configList.Append('=');
                    configList.Append(configuration);
                }
            }

            if (configList.Length > 0)
            {
                project.BuildProject.SetGlobalProperty("VSProjectConfigurations", configList.ToString());
            }
        }
Beispiel #23
0
        /// <summary>
        /// Cancels the solution build asynchronously
        /// </summary>
        /// <returns>Returns 'true' if successfull</returns>
        public async Task <bool> CancelBuildAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

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

            svc.CanCancelUpdateSolutionConfiguration(out int canCancel);

            if (canCancel == 0)
            {
                return(false);
            }

            return(svc.CancelUpdateSolutionConfiguration() == VSConstants.S_OK);
        }
Beispiel #24
0
 internal VsResetInteractive(
     VisualStudioWorkspace workspace,
     EnvDTE.DTE dte,
     IComponentModel componentModel,
     IVsMonitorSelection monitorSelection,
     IVsSolutionBuildManager buildManager,
     Func <string, string> createReference,
     Func <string, string> createImport)
     : base(componentModel.GetService <IEditorOptionsFactoryService>(), createReference, createImport)
 {
     _workspace        = workspace;
     _dte              = dte;
     _componentModel   = componentModel;
     _monitorSelection = monitorSelection;
     _buildManager     = buildManager;
 }
Beispiel #25
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);
        }
Beispiel #26
0
        public NunitView()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            emptyIcon   = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Empty.png"));
            successIcon = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Success.png"));
            failureIcon = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Failure.png"));
            abortedIcon = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Aborted.png"));
            runIcon     = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Run.png"));
            debugIcon   = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Debug.png"));
            stopIcon    = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Stop.png"));
            homeIcon    = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Support.png"));

            InitializeComponent();

            dataGridView1.AutoGenerateColumns = false;

            toolTip = new ToolTip();
            toolTip.AutoPopDelay = 5000;
            toolTip.InitialDelay = 1000;
            toolTip.ReshowDelay  = 500;
            toolTip.ShowAlways   = true;

            runTestsButton.Image = runIcon;
            toolTip.SetToolTip(runTestsButton, "Run All or Selected Tests");

            homeButton.Image = homeIcon;
            toolTip.SetToolTip(homeButton, "View Support Page");

            statusButton.Image = emptyIcon;

            uint         cookie;
            int          result          = 0;
            IVsSolution2 solutionService = (IVsSolution2)Package.GetGlobalService(typeof(SVsSolution));

            result = solutionService.AdviseSolutionEvents(this, out cookie);


            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Added solution service event listener: {0}", result));
            IVsSolutionBuildManager buildService = (IVsSolutionBuildManager)Package.GetGlobalService(typeof(SVsSolutionBuildManager));

            result = buildService.AdviseUpdateSolutionEvents(this, out cookie);
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Added build service event listener: {0}", result));

            RefreshView();
        }
Beispiel #27
0
        public VsSolutionManager(
            ISolutionBrowser solutionBrowser,
            IVsMonitorSelection monitorSelection,
            IVsSolutionBuildManager solutionBuildManager,
            IDiagLog log)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            this.solutionBrowser      = solutionBrowser ?? throw new ArgumentNullException(nameof(solutionBrowser));
            this.monitorSelection     = monitorSelection ?? throw new ArgumentNullException(nameof(monitorSelection));
            this.solutionBuildManager = solutionBuildManager ?? throw new ArgumentNullException(nameof(solutionBuildManager));
            this.log = log ?? throw new ArgumentNullException(nameof(log));

            // Advise to selection events (e.g. startup project changed)
            monitorSelection.AdviseSelectionEvents(this, out selectionEventsCookie);

            // Advise to update solution events (e.g. switched debug/release configuration)
            solutionBuildManager.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
        }
        //  -----------------------------------------------------
        /// <summary>
        /// Gets the hierarchy item corresponding to the startup project in
        /// the solution.
        /// </summary>
        /// <param name="sp">
        /// The service provider to use.
        /// </param>
        /// <returns>
        /// The startup project in the solution.
        /// </returns>
        public static HierarchyItem GetStartupProject(IServiceProvider sp)
        {
            IVsSolutionBuildManager manager =
                (IVsSolutionBuildManager)sp.GetService(
                    typeof(SVsSolutionBuildManager));

            IVsHierarchy hierarchy;

            manager.get_StartupProject(out hierarchy);

            if (hierarchy != null)
            {
                return(new HierarchyItem(hierarchy));
            }
            else
            {
                return(null);
            }
        }
        // ------------------------------------------------------
        /// <summary>
        /// Builds the solution in preparation for a test launch.
        /// </summary>
        public void BuildSolutionToRunTests()
        {
            TryToSetTestResultsText("Building the solution...");

            solutionBuildEvents.BuildingForTestLaunch = true;

            IVsSolutionBuildManager man = (IVsSolutionBuildManager)
                                          GetService(typeof(SVsSolutionBuildManager));

            uint flags = (uint)VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD;

            uint queryResults = (uint)(
                VSSOLNBUILDQUERYRESULTS.VSSBQR_CONTDEPLOYONERROR_QUERY_NO |
                VSSOLNBUILDQUERYRESULTS.VSSBQR_OUTOFDATE_QUERY_YES |
                VSSOLNBUILDQUERYRESULTS.VSSBQR_SAVEBEFOREBUILD_QUERY_YES);

            int result = man.StartSimpleUpdateSolutionConfiguration(
                flags, queryResults, 1);
        }
Beispiel #30
0
        /// <summary>
        /// Returns the startup project (based on the build manager).
        /// </summary>
        /// <returns></returns>
        public VsItemInfo GetStartupProject()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (_startupProject == null)
            {
                IVsSolutionBuildManager solutionBuildManager = GetVsSolutionBuildManager();

                if (solutionBuildManager != null)
                {
                    bool success = PackageHelper.Success(solutionBuildManager.get_StartupProject(out IVsHierarchy value));

                    if (success && value != null)
                    {
                        _startupProject = new VsItemInfo(value);
                    }
                }
            }
            return(_startupProject);
        }
Beispiel #31
0
        public static VsItemInfo GetStartupProject()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            VsItemInfo startupProject = null;
            IVsSolutionBuildManager solutionBuildManager = GetVsSolutionBuildManager();

            if (solutionBuildManager != null)
            {
                IVsHierarchy value   = null;
                bool         success = Success(solutionBuildManager.get_StartupProject(out value));

                if (success && value != null)
                {
                    startupProject = new VsItemInfo(value);
                }
            }

            return(startupProject);
        }
        public override void Initialize(ProjectSnapshotManagerBase projectManager)
        {
            _projectManager          = projectManager;
            _projectManager.Changed += ProjectManager_Changed;

            _ = _joinableTaskContext.Factory.RunAsync(async() =>
            {
                await _joinableTaskContext.Factory.SwitchToMainThreadAsync();

                // Attach the event sink to solution update events.
                if (_services.GetService(typeof(SVsSolutionBuildManager)) is IVsSolutionBuildManager solutionBuildManager)
                {
                    _solutionBuildManager = solutionBuildManager;

                    // We expect this to be called only once. So we don't need to Unadvise.
                    var hr = _solutionBuildManager.AdviseUpdateSolutionEvents(this, out _updateCookie);
                    Marshal.ThrowExceptionForHR(hr);
                }
            });
        }
Beispiel #33
0
    protected override void Initialize()
    {
      Common.Trace("Package intialize");
      base.Initialize();
      Common.Trace("Task manager.Initialize()");

      // Initialize common functionality
      Common.Initialize(this);
      taskListMenu = new RootMenu();
      
      // Initialize fields
      tools = new Tools();
      sharedTaskManagers = new List<TaskManager>();

      // Attach to solution events
      solution = GetService(typeof(SVsSolution)) as IVsSolution;
      if (solution == null) Common.Log("Could not get solution");
      solution.AdviseSolutionEvents(this as IVsSolutionEvents, out solutionEventsCookie);

      // Attach to build events
      buildManager = GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager;
      if (buildManager == null) Common.Log("Could not get build manager");
      buildManager.AdviseUpdateSolutionEvents(this, out buildManagerCookie);

      // Add a TaskManagerFactory service
      ITaskManagerFactory factory = this as ITaskManagerFactory;
      (this as System.ComponentModel.Design.IServiceContainer).AddService(typeof(ITaskManagerFactory), factory, true);

      // Set PID for msbuild tasks
      Environment.SetEnvironmentVariable( "VSPID", System.Diagnostics.Process.GetCurrentProcess().Id.ToString() );
    }
 public ProjectAsyncBuilder(IVsSolutionBuildManager manager, TaskCompletionSource<bool> completionSource)
 {
     _buildManager = manager;
     _completionSource = completionSource;
 }
Beispiel #35
0
    protected override void Initialize()
    {
      base.Initialize();
      
      // Initialize common functionality
      Common.Initialize(this);
      taskListMenu = new RootMenu();
      
      // Initialize fields
      tools = new Tools();
      sharedTaskManagers = new List<TaskManager>();

      // Attach to solution events
      solution = GetService(typeof(SVsSolution)) as IVsSolution;
      // if (solution == null) throw new NullReferenceException();
      solution.AdviseSolutionEvents(this as IVsSolutionEvents, out solutionEventsCookie);

      // Attach to build events
      buildManager = GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager;
      // if (buildManager == null) throw new NullReferenceException();
      buildManager.AdviseUpdateSolutionEvents(this, out buildManagerCookie);

      // Add a TaskManagerFactory service
      (this as System.ComponentModel.Design.IServiceContainer).AddService(typeof(ITaskManagerFactory), this, true);
    }
Beispiel #36
0
    protected override void Dispose(bool disposing)
    {
      if (disposing) {
        tools.Release();
        tools = null;

        sharedTaskManagers.Clear();
        sharedTaskManagers = null;

        if (buildManager != null) {
          buildManager.UnadviseUpdateSolutionEvents(buildManagerCookie);
          buildManager = null;
        }
        
        if (solution != null) {
          solution.UnadviseSolutionEvents(solutionEventsCookie);
          solution = null;
        }

        taskListMenu.Release();
        taskListMenu = null;
        Common.Release();
        GC.SuppressFinalize(this);
      }
      base.Dispose(disposing);
    }