/// <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(); KUE4VS.Logging.Initialize(ExtensionName, VersionString); KUE4VS.Logging.WriteLine("Loading UnrealVS extension package..."); dte = GetGlobalService(typeof(DTE)) as DTE2; sln_mgr = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)) as IVsSolution2; sln_mgr.AdviseSolutionEvents(this, out SolutionEventsHandle); build_mgr = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; KUE4VS.ExtContext.Instance = this; PackageProvider.Pkg = this; UE4PropVis.Config.Instance = (UE4PropVis.Config)GetDialogPage(typeof(UE4PropVis.Config)); UpdateUnrealLoadedStatus(); AddNewSourceFileCmd.Initialize(this); AddNewClassCmd.Initialize(this); AddNewModuleCmd.Initialize(this); AddNewPluginCmd.Initialize(this); AddCodeElementWindowCommand.Initialize(this); }
public ProjectBuilder2015( IVsSolutionBuildManager2 buildManager, IVSThreadingService threadingService, IProjectMapper projectMapper) : base(buildManager, threadingService, projectMapper) { }
public void Deinitalize() { ThreadHelper.ThrowIfNotOnUIThread(); // Cleanup solution related stuff if (selectionEventsCookie != 0) { ErrorHandler.ThrowOnFailure(this.selectionMonitor.UnadviseSelectionEvents(selectionEventsCookie)); } if (updateSolutionEventsCookie != 0) { ErrorHandler.ThrowOnFailure(this.solutionBuildService.UnadviseUpdateSolutionEvents(updateSolutionEventsCookie)); } selectionEventsCookie = 0; updateSolutionEventsCookie = 0; this.solutionService = null; this.solutionBuildService = null; this.selectionMonitor = null; commandEvents.BeforeExecute -= CommandEventsOnBeforeExecute; initialized = false; }
protected override void Initialize() { base.Initialize(); //if invalid data, adjust it dataAdjuster.Adjust(); // Get solution build manager sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (sbm != null) { sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie); } // Must hold a reference to the solution events object or the events wont fire, garbage collection related events = GetDTE().Events.SolutionEvents; events.Opened += Solution_Opened; PrintLine("Build monitor initialized"); PrintLine("Path to persist data: {0}", Settings.RepositoryPath); monitor.SolutionBuildFinished = b => { Print("[{0}] Time Elapsed: {1} \t\t", b.SessionBuildCount, b.SolutionBuildTime.ToTime()); PrintLine("Session build time: {0}\n", b.SessionMillisecondsElapsed.ToTime()); }; monitor.ProjectBuildFinished = b => PrintLine(" - {0}\t-- {1} --", b.MillisecondsElapsed.ToTime(), b.ProjectName); }
/// <summary> /// Initialization of the package. /// </summary> protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); //await base.InitializeAsync(cancellationToken, progress); dte = await GetServiceAsync(typeof(DTE)) as DTE2; //GetGlobalService(typeof(DTE)) as DTE2; sln_mgr = await GetServiceAsync(typeof(SVsSolution)) as IVsSolution2; UpdateUnrealLoadedStatus(); sln_mgr.AdviseSolutionEvents(this, out SolutionEventsHandle); build_mgr = await GetServiceAsync(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; KUE4VS.ExtContext.Instance = this; PackageProvider.Pkg = this; UE4PropVis.Config.Instance = (UE4PropVis.Config)GetDialogPage(typeof(UE4PropVis.Config)); AddNewSourceFileCmd.Initialize(this); AddNewClassCmd.Initialize(this); AddNewModuleCmd.Initialize(this); AddNewPluginCmd.Initialize(this); AddCodeElementWindowCommand.Initialize(this); base.Initialize(); }
public DefaultProjectBuilder( IVsSolutionBuildManager2 buildManager, IProjectMapper projectMapper) { ProjectMapper = projectMapper; _buildManager = buildManager; }
protected override void Initialize() { base.Initialize(); //if invalid data, adjust it dataAdjuster.Adjust(); // Get solution build manager sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (sbm != null) { sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie); } // Must hold a reference to the solution events object or the events wont fire, garbage collection related events = GetDTE().Events.SolutionEvents; events.Opened += Solution_Opened; GetDTE().Events.BuildEvents.OnBuildBegin += Build_Begin; PrintLine("Build monitor initialized"); PrintLine("Path to persist data: {0}", Settings.RepositoryPath); monitor.SolutionBuildFinished = b => { Print("[{0}] Time Elapsed: {1} \t\t", b.SessionBuildCount, b.SolutionBuildTime.ToTime()); PrintLine("Session build time: {0}\n", b.SessionMillisecondsElapsed.ToTime()); PrintLine("Rebuild All: {0}\n", b.SolutionBuild.IsRebuildAll); System.Threading.Tasks.Task.Factory.StartNew(() => SaveToDatabase(b)); }; monitor.ProjectBuildFinished = b => PrintLine(" - {0}\t-- {1} --", b.MillisecondsElapsed.ToTime(), b.ProjectName); AnalyseBuildTimesCommand.Initialize(this); }
internal UpdateSolutionEvents(IVsSolutionBuildManager2 solutionBuildManager) { ThreadHelper.ThrowIfNotOnUIThread(); _solutionBuildManager = solutionBuildManager; ErrorHandler.ThrowOnFailure(solutionBuildManager.AdviseUpdateSolutionEvents(this, out _cookie)); }
/// <summary> /// Retrives the configuration and the platform using the IVsSolutionBuildManager2 interface. /// </summary> /// <param name="serviceProvider">A service provider.</param> /// <param name="hierarchy">The hierarchy whose configuration is requested. This method calls into /// native code and may be called on a background thread, so make sure the IVsHierarchy passed is /// safe to use for that sort of interop.</param> /// <param name="configuration">The name of the active configuration.</param> /// <param name="platform">The name of the platform.</param> /// <returns>true if successfull.</returns> /// <summary> /// Retrives the configuration and the platform using the IVsSolutionBuildManager2 interface. /// </summary> /// <param name="serviceProvider">A service provider.</param> /// <param name="hierarchy">The hierrachy whose configuration is requested.</param> /// <param name="configuration">The name of the active configuration.</param> /// <param name="platform">The name of the platform.</param> /// <returns>true if successfull.</returns> internal static bool TryGetActiveConfigurationAndPlatform(System.IServiceProvider serviceProvider, IVsHierarchy hierarchy, out ConfigCanonicalName configCanonicalName) { if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } if (hierarchy == null) { throw new ArgumentNullException("hierarchy"); } IVsSolutionBuildManager2 solutionBuildManager = serviceProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (solutionBuildManager == null) { configCanonicalName = new ConfigCanonicalName(); return(false); } IVsProjectCfg[] activeConfigs = new IVsProjectCfg[1]; ErrorHandler.ThrowOnFailure(solutionBuildManager.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy, activeConfigs)); IVsProjectCfg activeCfg = activeConfigs[0]; // Can it be that the activeCfg is null? System.Diagnostics.Debug.Assert(activeCfg != null, "Cannot find the active configuration"); string canonicalName; ErrorHandler.ThrowOnFailure(activeCfg.get_CanonicalName(out canonicalName)); configCanonicalName = new ConfigCanonicalName(canonicalName); return(true); }
internal void Register() { // Register this object to listen for IVsUpdateSolutionEvents IVsSolutionBuildManager2 buildManager = Package.GetService <SVsSolutionBuildManager, IVsSolutionBuildManager2>(); if (buildManager == null) { throw Marshal.GetExceptionForHR(E_FAIL); } buildManager.AdviseUpdateSolutionEvents(this, out m_updateSolutionEventsCookie); // Register this object to listen for IVsSolutionEvents IVsSolution solution = Package.GetService <SVsSolution, IVsSolution>(); if (solution == null) { throw Marshal.GetExceptionForHR(E_FAIL); } solution.AdviseSolutionEvents(this, out m_solutionEventsCookie); // Register this object to listen for IVsRunningDocTableEvents _runningDocTable = Package.GetService <SVsRunningDocumentTable, IVsRunningDocumentTable>(); if (_runningDocTable == null) { throw Marshal.GetExceptionForHR(E_FAIL); } _runningDocTable.AdviseRunningDocTableEvents(this, out m_runningDocTableEventsCookie); }
internal void Unregister() { // Unregister this object from IVsUpdateSolutionEvents events if (m_updateSolutionEventsCookie != VSCOOKIE_NIL) { IVsSolutionBuildManager2 buildManager = Package.GetService <SVsSolutionBuildManager, IVsSolutionBuildManager2>(); if (buildManager != null) { buildManager.UnadviseUpdateSolutionEvents(m_updateSolutionEventsCookie); m_updateSolutionEventsCookie = VSCOOKIE_NIL; } } // Unregister this object from IVsSolutionEvents events if (m_solutionEventsCookie != VSCOOKIE_NIL) { IVsSolution solution = Package.GetService <SVsSolution, IVsSolution>(); if (solution != null) { solution.UnadviseSolutionEvents(m_solutionEventsCookie); m_solutionEventsCookie = VSCOOKIE_NIL; } } // Unregister this object from IVsRunningDocTableEvents events if (m_runningDocTableEventsCookie != VSCOOKIE_NIL) { IVsRunningDocumentTable runningDocTable = Package.GetService <SVsRunningDocumentTable, IVsRunningDocumentTable>(); if (runningDocTable != null) { runningDocTable.UnadviseRunningDocTableEvents(m_runningDocTableEventsCookie); m_runningDocTableEventsCookie = VSCOOKIE_NIL; } } }
public void Initialize() { if (!initialized) { // Setup solution related stuff this.solutionService = package.GetService <SVsSolution, IVsSolution2>(); this.solutionBuildService = package.GetService <SVsSolutionBuildManager, IVsSolutionBuildManager2>(); this.selectionMonitor = package.GetService <SVsShellMonitorSelection, IVsMonitorSelection>(); // Set startup project ErrorHandler.ThrowOnFailure(this.solutionService.AdviseSolutionEvents(this, out solutionEventsCookie)); ErrorHandler.ThrowOnFailure(this.selectionMonitor.AdviseSelectionEvents(this, out selectionEventsCookie)); ErrorHandler.ThrowOnFailure(this.solutionBuildService.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie)); commandEvents = this.appObject.Events.CommandEvents; commandEvents.BeforeExecute += CommandEventsOnBeforeExecute; if (IsSolutionOpen) { foreach (var pHierarchy in GetSupportedProjects()) { Guid projectGuid = pHierarchy.GetGuid(); string projectDir = pHierarchy.GetProjectDir(); string projectName = pHierarchy.GetName(); ProjectStateMap[projectGuid] = new ProjectState { ProjectDir = projectDir, ProjectName = projectName, IsLoaded = true }; } } initialized = true; } }
protected override void Initialize() { Trace.WriteLine(String.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); base.Initialize(); try { errorList = new VSTools.ErrorList.Pane(this); Log._.Received -= onLogReceived; Log._.Received += onLogReceived; initAppEvents(); OleMenuCommandService mcs = (OleMenuCommandService)GetService(typeof(IMenuCommandService)); // Build / <Main App> _menuItemMain = new MenuCommand(_menuMainCallback, new CommandID(GuidList.MAIN_CMD_SET, (int)PkgCmdIDList.CMD_MAIN)); _menuItemMain.Visible = false; mcs.AddCommand(_menuItemMain); // View / Other Windows / <Status Panel> mcs.AddCommand(new MenuCommand(_menuPanelCallback, new CommandID(GuidList.PANEL_CMD_SET, (int)PkgCmdIDList.CMD_PANEL))); // To listen events that fired as a IVsSolutionEvents spSolution = (IVsSolution)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)); spSolution.AdviseSolutionEvents(this, out _pdwCookieSolution); // To listen events that fired as a IVsUpdateSolutionEvents2 spSolutionBM = (IVsSolutionBuildManager2)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)); spSolutionBM.AdviseUpdateSolutionEvents(this, out _pdwCookieSolutionBM); } catch (Exception ex) { string msg = string.Format("{0}\n{1}\n\n-----\n{2}", "Something went wrong -_-", "Try to restart IDE or reinstall current plugin in Extension Manager.", ex.ToString()); Debug.WriteLine(msg); int res; Guid id = Guid.Empty; IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure( uiShell.ShowMessageBox( 0, ref id, "Initialize vsSolutionBuildEvent", msg, string.Empty, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_WARNING, 0, out res)); } }
public IVsSolutionBuildManager2 Provide() { // TODO check result and manage failure IVsSolutionBuildManager2 solutionBuildManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; return(solutionBuildManager); }
private void HookBuildEvents() { // Get solution build manager sbm = ServiceProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (sbm != null) { sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie); } }
private void SubscribeToUpdateSolutionEvents() { // Get solution build manager _solutionBuildManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (_solutionBuildManager != null) { _solutionBuildManager.AdviseUpdateSolutionEvents(this, out _updateSolutionEventsCookie); } }
private ProjectBuilder ProjectBuilderAfterBuildHasBegun(IVsSolutionBuildManager2 buildManager) { var project = Substitute.For<Project>(); var projectBuilder = new ProjectBuilder(buildManager); projectBuilder.BuildAsync(new List<Project> { project }); return projectBuilder; }
public BuildEvents() { // Get solution build manager buildManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (buildManager != null) { buildManager.AdviseUpdateSolutionEvents(this, out eventsCookie); } }
protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { // Switches to the UI thread, which most of this package requires. Even joining the main thread here improves // the load time of the package, and it stops a warning popping up when you load vs2019 with the package installed. await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); await base.InitializeAsync(cancellationToken, progress); output = new OutputWindowWrapper(this); SettingsManager settingsManager = new ShellSettingsManager(ServiceProvider.GlobalProvider); WritableSettingsStore settingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings); Settings.Instance = new Settings(settingsStore); var factory = new BuildFactory(); var repository = new BuildRepository(Settings.Instance.RepositoryPath); monitor = new BuildMonitor.Domain.Monitor(factory, repository); dataAdjuster = new DataAdjusterWithLogging(repository, output.WriteLine); //if invalid data, adjust it dataAdjuster.Adjust(); // Get solution build manager sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (sbm != null) { sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie); } // Must hold a reference to the solution events object or the events wont fire, garbage collection related events = GetDTE().Events.SolutionEvents; events.Opened += Solution_Opened; GetDTE().Events.BuildEvents.OnBuildBegin += Build_Begin; output.WriteLine("Build monitor initialized"); output.WriteLine("Path to persist data: {0}", Settings.Instance.RepositoryPath); monitor.SolutionBuildFinished = b => { output.Write("[{0}] Time Elapsed: {1} \t\t", b.SessionBuildCount, b.SolutionBuildTime.ToTime()); output.WriteLine("Session build time: {0}\n", b.SessionMillisecondsElapsed.ToTime()); output.WriteLine("Rebuild All: {0}\n", b.SolutionBuild.IsRebuildAll); //System.Threading.Tasks.Task.Factory.StartNew(() => SaveToDatabase(b)); }; monitor.ProjectBuildFinished = b => output.WriteLine(" - {0}\t-- {1} --", b.MillisecondsElapsed.ToTime(), b.ProjectName); // In vs 2017 and earlier, this event was always called, but in 2019 it isn't called if you open a solution on startup. // I imagine this is because the solution has already loaded before we connect to the events. To get over it we just // manually call the event here. Solution_Opened(); AnalyseBuildTimesCommand.Initialize(this); }
public DefaultProjectBuilder( IVsSolutionBuildManager2 buildManager, IVSThreadingService threadingService, IProjectMapper projectMapper) { _projectMapper = projectMapper; _threadingService = threadingService; _buildManager = buildManager; }
internal UpdateSolutionEvents(IVsSolutionBuildManager2 solutionBuildManager) { this.solutionBuildManager = solutionBuildManager; var hresult = solutionBuildManager.AdviseUpdateSolutionEvents(this, out cookie); if (hresult != 0) { System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(hresult); } }
/// <summary> /// Defines listeners for main events. /// </summary> private void adviseEvents() { // To listen events that fired as a IVsSolutionEvents spSolution = (IVsSolution)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)); spSolution.AdviseSolutionEvents(this, out _pdwCookieSolution); // To listen events that fired as a IVsUpdateSolutionEvents2 spSolutionBM = (IVsSolutionBuildManager2)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)); spSolutionBM.AdviseUpdateSolutionEvents(this, out _pdwCookieSolutionBM); }
private ProjectBuilder ProjectBuilderAfterBuildHasBegun(IVsSolutionBuildManager2 buildManager) { var project = Substitute.For <Project>(); var projectBuilder = new ProjectBuilder(buildManager); projectBuilder.BuildAsync(new List <Project> { project }); return(projectBuilder); }
/// <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> /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param> /// <param name="progress">A provider for progress updates.</param> /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns> protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { this.dte2 = (await this.GetServiceAsync(typeof(SDTE)).ConfigureAwait(false)) as DTE2; if (this.dte2 == null) { Trace.TraceError("VSPackage.Initialize() could not obtain DTE2 reference"); return; } await JoinableTaskFactory.SwitchToMainThreadAsync(); if (this.dte2.Solution == null || string.IsNullOrEmpty(this.dte2.Solution.FullName)) { return; } string solutionFilePath = this.dte2.Solution.FullName; string solutionFolder = Path.GetDirectoryName(solutionFilePath); string solutionFileName = Path.GetFileNameWithoutExtension(solutionFilePath); var preBuildFile = Path.Combine(solutionFolder, $"{solutionFileName}.PreBuild.ps1"); if (File.Exists(preBuildFile)) { Trace.WriteLine("prebuild.ps1 found"); this.hasPrebuild = true; this.PreBuildScript = $"&{{ {File.ReadAllText(preBuildFile)} }} -Verbose -Debug *>&1"; } var postBuildFile = Path.Combine(solutionFolder, $"{solutionFileName}.PostBuild.ps1"); if (File.Exists(postBuildFile)) { Trace.WriteLine("postbuild.ps1 found"); this.hasPostbuild = true; this.PostBuildScript = $"&{{ {File.ReadAllText(postBuildFile)} }} -Verbose -Debug *>&1"; } if (this.hasPostbuild == false && this.hasPrebuild == false) { return; } // When initialized asynchronously, the current thread may be a background thread at this point. // Do any initialization that requires the UI thread after switching to the UI thread. await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); this.solutionBuildManager = (await this.GetServiceAsync(typeof(SVsSolutionBuildManager)).ConfigureAwait(false)) as IVsSolutionBuildManager2; if (this.solutionBuildManager != null) { this.solutionBuildManager.AdviseUpdateSolutionEvents(this, out this.updateSolutionEventsCookie); } await CreatePaneAsync(paneGuid, "VisualStudioBuildExtension", true, false); }
public static bool RunCloneDetective(EventHandler <CloneDetectiveCompletedEventArgs> completedHandler) { string solutionPath = VSPackage.Instance.GetSolutionPath(); // Save all modified documents before we start the build. Pay attention // to the fact that the user can cancel this operation. IVsSolutionBuildManager2 solutionBuildManager = (IVsSolutionBuildManager2)VSPackage.Instance.GetService(typeof(SVsSolutionBuildManager)); int hr = solutionBuildManager.SaveDocumentsBeforeBuild(null, 0, 0); if (hr == VSConstants.E_ABORT) { return(false); } VSPackage.Instance.ClearOutput(); _cloneDetectiveRunner = new CloneDetectiveRunner(solutionPath); _cloneDetectiveRunner.Started += (sender, e) => WriteStartedMessage(e); _cloneDetectiveRunner.Message += (sender, e) => WriteOutputMessage(e); _cloneDetectiveRunner.Completed += (sender, e) => { WriteCompletedMessage(e); _cloneDetectiveRunner = null; if (e.Result != null) { CloneDetectiveResult = e.Result; } completedHandler(sender, e); }; // Validate path to ConQAT.bat if (!File.Exists(GlobalSettings.GetConqatBatFileName())) { VSPackage.Instance.ShowError(Res.InvalidConqatBatPath); return(false); } // Validate Java Home. if (!File.Exists(Path.Combine(Path.Combine(GlobalSettings.GetJavaHome(), "bin"), "Java.exe"))) { VSPackage.Instance.ShowError(Res.InvalidJavaExePath); return(false); } // Now run the clone detective. _cloneDetectiveRunner.RunAsync(); return(true); }
private async Task EnsureBuildManagerInitializedAsync() { // Switch to UI thread for querying the build manager service. await _threadingService.SwitchToUIThread(); if (_buildManager == null) { _buildManager = _serviceProvider.GetService <IVsSolutionBuildManager2, SVsSolutionBuildManager>(); // Register for solution build events. _buildManager.AdviseUpdateSolutionEvents(this, out _solutionEventsCookie); } }
/// <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(); _solutionBuildManager = ServiceProvider.GlobalProvider.GetService( typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; Throw.IfNull(_solutionBuildManager, "_solutionBuildManager"); ErrorHandler.ThrowOnFailure( _solutionBuildManager.AdviseUpdateSolutionEvents(this, out _updateSolutionEventsCookie)); }
private void UnsubscribeUpdateSolutionEvents() { if (_solutionBuildManager != null) { if (_updateSolutionEventsCookie != 0) { _solutionBuildManager.UnadviseUpdateSolutionEvents(_updateSolutionEventsCookie); _updateSolutionEventsCookie = 0; } _solutionBuildManager = null; } }
private bool IsReferenceInCycle(Guid projectGuid) { // use same logic as C#: // vsproject\langbuild\langref.cpp // BOOL CLanguageReferences::IsCircularReference(CLangReference *pclref, BOOL fCalculateDependencies) int isCircular = 0; IVsHierarchy otherHier = VsShellUtilities.GetHierarchy(this.ProjectMgr.Site, projectGuid); IVsSolutionBuildManager2 vsSBM = this.ProjectMgr.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; vsSBM.CalculateProjectDependencies(); vsSBM.QueryProjectDependency(otherHier, this.ProjectMgr.InteropSafeIVsHierarchy, out isCircular); return(isCircular != 0); }
///////////////////////////////////////////////////////////////////////////// // Overridden Package Implementation #region Package Members /// <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() { Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this)); base.Initialize(); this.dte2 = this.GetService(typeof(SDTE)) as DTE2; if (this.dte2 == null) { Log.LogError("VSPackage.Initialize() could not obtain DTE2 reference"); return; } this.RefreshMSBuildOutputVerbositySetting(); // Get solution build manager this.solutionBuildManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (this.solutionBuildManager != null) { this.solutionBuildManager.AdviseUpdateSolutionEvents(this, out this.updateSolutionEventsCookie); } IVsOutputWindow outputWindow = this.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow; if (outputWindow == null) { Log.LogError("VSPackage.Initialize() could not obtain IVsOutputWindow reference"); return; } Guid buildPaneGuid = VSConstants.GUID_BuildOutputWindowPane; int hResult = outputWindow.GetPane(ref buildPaneGuid, out this.buildOutputWindowPane); if (hResult != VSConstants.S_OK || this.buildOutputWindowPane == null) { Log.LogError("VSPackage.Initialize() could not obtain IVsOutputWindowPane reference"); return; } GuidAttribute VSStd97CmdIDGuidAttribute = typeof(VSConstants.VSStd97CmdID).GetCustomAttributes(typeof(GuidAttribute), true)[0] as GuidAttribute; Debug.Assert(VSStd97CmdIDGuidAttribute != null, "VSStd97CmdIDGuidAttribute != null"); this.VSStd97CmdIDGuid = "{" + VSStd97CmdIDGuidAttribute.Value + "}"; GuidAttribute VSStd2KCmdIDGuidAttribute = typeof(VSConstants.VSStd2KCmdID).GetCustomAttributes(typeof(GuidAttribute), true)[0] as GuidAttribute; Debug.Assert(VSStd2KCmdIDGuidAttribute != null, "VSStd2KCmdIDGuidAttribute != null"); this.VSStd2KCmdIDGuid = "{" + VSStd2KCmdIDGuidAttribute.Value + "}"; this.commandEvents = this.dte2.Events.CommandEvents; this.commandEvents.BeforeExecute += this.CommandEvents_BeforeExecute; }
private DefaultProjectBuilder ProjectBuilderAfterBuildHasBegun(IVsSolutionBuildManager2 buildManager) { var project = Substitute.For <Project>(); var projectMapper = Substitute.For <IProjectMapper>(); var threading = Substitute.For <IVSThreadingService>(); var projectBuilder = new DefaultProjectBuilder(buildManager, threading, projectMapper); projectBuilder.BuildAsync(new List <Project> { project }); return(projectBuilder); }
public BuildTracker( DTE2 vsInstance, IVsSolutionBuildManager2 buildManager, BuildRestartSettings settings ) { Ensure.That(() => vsInstance).IsNotNull(); Ensure.That(() => settings).IsNotNull(); Ensure.That(() => buildManager).IsNotNull(); _vsInstance = vsInstance; _settings = settings; _buildManager = buildManager; _buildManager.AdviseUpdateSolutionEvents(this, out uint pdwCookieSolutionBM); }
/// <summary> /// Overloaded constructor. /// </summary> /// <param name="serviceProvider">A service provider.</param> public UpdateSolutionEventsListener(IServiceProvider serviceProvider) { if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } this.serviceProvider = serviceProvider; this.solutionBuildManager = this.serviceProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (this.solutionBuildManager == null) { throw new InvalidOperationException(); } ErrorHandler.ThrowOnFailure(this.solutionBuildManager.AdviseUpdateSolutionEvents(this, out this.solutionEvents2Cookie)); Debug.Assert(this.solutionBuildManager is IVsSolutionBuildManager3, "The solution build manager object implementing IVsSolutionBuildManager2 does not implement IVsSolutionBuildManager3"); ErrorHandler.ThrowOnFailure(this.SolutionBuildManager3.AdviseUpdateSolutionEvents3(this, out this.solutionEvents3Cookie)); }
public BuildTracker( DTE2 vsInstance, IVsSolutionBuildManager2 buildManager, BuildHelperSettings settings, WinHelper winHelper) { Ensure.That(() => vsInstance).IsNotNull(); Ensure.That(() => settings).IsNotNull(); Ensure.That(() => winHelper).IsNotNull(); Ensure.That(() => buildManager).IsNotNull(); m_VsInstance = vsInstance; m_Settings = settings; m_WinHelper = winHelper; uint pdwCookieSolutionBM; m_BuildManager = buildManager; m_BuildManager.AdviseUpdateSolutionEvents(this, out pdwCookieSolutionBM); }
/// <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(); ActivateBuildOrderPaneCmd.Initialize(this); // Get solution build manager _solutionBuildManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (_solutionBuildManager != null) _solutionBuildManager.AdviseUpdateSolutionEvents(this, out _updateSolutionEventsCookie); _outputWindow = (IVsOutputWindow)GetService(typeof(SVsOutputWindow)); if (_outputWindow != null) { _outputWindow.GetPane(VSConstants.OutputWindowPaneGuid.SortedBuildOutputPane_guid, out _buildOrderPane); } }
/// <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(); // Add our command handlers for menu (commands must exist in the .vsct file) OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { // Create the command for the tool window CommandID toolwndCommandID = new CommandID(GuidList.guidProgressBarCmdSet, (int)PkgCmdIDList.cmdidProgressBar); MenuCommand menuToolWin = new MenuCommand(ShowToolWindow, toolwndCommandID); mcs.AddCommand(menuToolWin); } // Get shell object vsShell = ServiceProvider.GlobalProvider.GetService(typeof(SVsShell)) as IVsShell; if (vsShell != null) { // Initialize VisualEffects values, so themes can determine if various effects are supported by the environment object effectsAllowed; if (ErrorHandler.Succeeded(vsShell.GetProperty((int)__VSSPROPID4.VSSPROPID_VisualEffectsAllowed, out effectsAllowed))) { // VSSPROPID_VisualEffectsAllowed is a VT_I4 property, so casting to int should be safe Debug.Assert(effectsAllowed is int, "VSSPROPID_VisualEffectsAllowed should be of type int"); this.visualEffectsAllowed = (int)effectsAllowed; } else { Debug.Fail("Failed to get the VSSPROPID_VisualEffectsAllowed property value."); } // Subscribe to shell property changes to update VisualEffects values if the user modifies the settings vsShell.AdviseShellPropertyChanges(this, out shellPropertyChangesCookie); } // Get solution solution = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)) as IVsSolution2; if (solution != null) { // Get count of any currently loaded projects object count; solution.GetProperty((int)__VSPROPID.VSPROPID_ProjectCount, out count); totalProjects = (int)count; // Register for solution events solution.AdviseSolutionEvents(this, out solutionEventsCookie); } // Get solution build manager sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (sbm != null) { sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie); } // Get tool window if (toolWindow == null) { toolWindow = this.FindToolWindow(typeof(BuildProgressToolWindow), 0, true) as BuildProgressToolWindow; } // Set initial value of EffectsEnabled in tool window toolWindow.EffectsEnabled = visualEffectsAllowed != 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() { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); base.Initialize(); // Add our command handlers for menu (commands must exist in the .vsct file) OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if(null != mcs) { // Create the command for the menu item. CommandID menuCommandID = new CommandID(GuidList.guidMetaCmdSet1, (int)PkgCmdIDList.cmdidMetaUIContext1); OleMenuCommand menuItem = new OleMenuCommand(BuildProfileCallback, menuCommandID); menuItem.BeforeQueryStatus += uiContex1Cmd_BeforeQueryStatus; mcs.AddCommand(menuItem); menuCommandID = new CommandID(GuidList.guidMetaCmdSet2, (int)PkgCmdIDList.cmdidMetaUIContext1); menuItem = new OleMenuCommand(BuildProfileCallback, menuCommandID); menuItem.BeforeQueryStatus += uiContex1Cmd_BeforeQueryStatus; mcs.AddCommand(menuItem); menuCommandID = new CommandID(GuidList.guidMetaCmdSet2, (int)PkgCmdIDList.cmdidMetaUIContext2); menuItem = new OleMenuCommand(TemplateProfileCallback, menuCommandID); menuItem.BeforeQueryStatus += uiContex2Cmd_BeforeQueryStatus; mcs.AddCommand(menuItem); } // Get shell object vsShell = ServiceProvider.GlobalProvider.GetService(typeof(SVsShell)) as IVsShell; if(vsShell != null) vsShell.AdviseShellPropertyChanges(this, out shellPropertyChangesCookie); // Get solution solution = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)) as IVsSolution2; if(solution != null) { // Get count of any currently loaded projects object count; solution.GetProperty((int)__VSPROPID.VSPROPID_ProjectCount, out count); // Register for solution events solution.AdviseSolutionEvents(this, out solutionEventsCookie); } // Get solution build manager sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if(sbm != null) sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie); }
/// <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 initilaization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { Trace.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); base.Initialize(); // Get solution build manager _buildManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (_buildManager != null) _buildManager.AdviseUpdateSolutionEvents(this, out _solutionBuildEventsCookie); }
protected override void Initialize() { Trace.WriteLine(String.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); base.Initialize(); try { initAppEvents(); OleMenuCommandService mcs = (OleMenuCommandService)GetService(typeof(IMenuCommandService)); // Build / <Main App> _menuItemMain = new MenuCommand(_menuMainCallback, new CommandID(GuidList.MAIN_CMD_SET, (int)PkgCmdIDList.CMD_MAIN)); _menuItemMain.Visible = false; mcs.AddCommand(_menuItemMain); // View / Other Windows / <Status Panel> mcs.AddCommand(new MenuCommand(_menuPanelCallback, new CommandID(GuidList.PANEL_CMD_SET, (int)PkgCmdIDList.CMD_PANEL))); // To listen events that fired as a IVsSolutionEvents spSolution = (IVsSolution)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)); spSolution.AdviseSolutionEvents(this, out _pdwCookieSolution); // To listen events that fired as a IVsUpdateSolutionEvents2 spSolutionBM = (IVsSolutionBuildManager2)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)); spSolutionBM.AdviseUpdateSolutionEvents(this, out _pdwCookieSolutionBM); } catch(Exception ex) { string msg = string.Format("{0}\n{1}\n\n-----\n{2}", "Something went wrong -_-", "Try to restart IDE or reinstall current plugin in Extension Manager.", ex.ToString()); Log.Fatal(msg); int res; Guid id = Guid.Empty; IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure( uiShell.ShowMessageBox( 0, ref id, "Initialize vsSolutionBuildEvent", msg, string.Empty, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_WARNING, 0, out res)); } }
private void InitializePackage() { // Get shell object vsShell = ServiceProvider.GlobalProvider.GetService(typeof(SVsShell)) as IVsShell; // Get solution solution = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)) as IVsSolution2; if (solution != null) { // Get count of any currently loaded projects object count; solution.GetProperty((int)__VSPROPID.VSPROPID_ProjectCount, out count); var totalProjects = (int)count; // Register for solution events solution.AdviseSolutionEvents(this, out solutionEventsCookie); } // Get solution build manager sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (sbm != null) { sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie); } /* // Get build manager bm = ServiceProvider.GlobalProvider.GetService(typeof (IVsSolutionBuildManager)) as IVsSolutionBuildManager; if (bm != null) { //bm.AdviseUpdateSolutionEvents(this, out someCookie); } */ /* mon = ServiceProvider.GlobalProvider.GetService(typeof (IVsMonitorSelection)) as IVsMonitorSelection; IVsMultiItemSelect mms; IntPtr ppHier, ppSc; uint ppmms = VSConstants.VSITEMID_SELECTION; mon.GetCurrentSelection(out ppHier, out ppmms, out mms, out ppSc); IVsHierarchy hierarchy = Marshal.GetTypedObjectForIUnknown(ppHier, typeof(IVsHierarchy)) as IVsHierarchy; */ //hier = ServiceProvider.GlobalProvider.GetService(typeof(IVsHierarchy)) as IVsHierarchy; _applicationObject = (DTE)GetService(typeof(DTE)); // string solutionDir = System.IO.Path.GetDirectoryName(_applicationObject.Solution.FullName); /* var doc = _applicationObject.ActiveDocument; var projectItem = doc.ProjectItem; var project = projectItem.ContainingProject; var evalProject = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.LoadProject(project.FullName); var execProject = evalProject.CreateProjectInstance(); */ }
public ProjectBuilder(IVsSolutionBuildManager2 buildManager) { _buildManager = buildManager; }
public void Initialize() { if (!initialized) { // Setup solution related stuff this.solutionService = package.GetService<SVsSolution, IVsSolution2>(); this.solutionBuildService = package.GetService<SVsSolutionBuildManager, IVsSolutionBuildManager2>(); this.selectionMonitor = package.GetService<SVsShellMonitorSelection, IVsMonitorSelection>(); // Set startup project ErrorHandler.ThrowOnFailure(this.selectionMonitor.AdviseSelectionEvents(this, out selectionEventsCookie)); ErrorHandler.ThrowOnFailure(this.solutionBuildService.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie)); initialized = true; } }
/// <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() { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); base.Initialize(); // Get solution solution = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)) as IVsSolution2; if (solution != null) { // Get count of any currently loaded projects object count; solution.GetProperty((int)__VSPROPID.VSPROPID_ProjectCount, out count); // Register for solution events solution.AdviseSolutionEvents(this, out solutionEventsCookie); } // Get solution build manager sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (sbm != null) { sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie); } }
public void Deinitalize() { // Cleanup solution related stuff if (selectionEventsCookie != 0) ErrorHandler.ThrowOnFailure(this.selectionMonitor.UnadviseSelectionEvents(selectionEventsCookie)); if (updateSolutionEventsCookie != 0) ErrorHandler.ThrowOnFailure(this.solutionBuildService.UnadviseUpdateSolutionEvents(updateSolutionEventsCookie)); selectionEventsCookie = 0; updateSolutionEventsCookie = 0; this.solutionService = null; this.solutionBuildService = null; this.selectionMonitor = null; initialized = false; }