public static void Initialize() { if (ServiceProviderRegistration.GlobalProvider.GetService(typeof(SVsSettingsManager)) != null) { return; } var esm = ExternalSettingsManager.CreateForApplication(GetVersionExe(FindVsVersions().LastOrDefault().ToString())); var sp = new ServiceProviderMock { serviceInstances = { // Used by ServiceProvider { typeof(SVsActivityLog).GUID, new DummyLog() }, { typeof(SVsSettingsManager).GUID, new SettingsWrapper(esm) } } }; ServiceProviderRegistration.CreateFromSetSite(sp); // The designer loads Microsoft.VisualStudio.Shell.XX.0, // which we cannot reference directly (to avoid breaking // older versions). Therefore, I set the global property // for every available version using Reflection instead. foreach (var vsVersion in FindVsVersions().Where(v => v.Major >= 10)) { var type = Type.GetType("Microsoft.VisualStudio.Shell.ServiceProvider, Microsoft.VisualStudio.Shell." + vsVersion.ToString(2)); if (type == null) { continue; } type.GetMethod("CreateFromSetSite", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static) .Invoke(null, new[] { sp }); } }
public void TestOpenAndCloseIDE() { Assert.Equal("devenv", Process.GetCurrentProcess().ProcessName); var dte = (DTE)ServiceProvider.GetService(typeof(_DTE)); Assert.NotNull(dte); }
public FoxProEngineProvider(IOleServiceProvider serviceProvider) { if (null != serviceProvider) { this.serviceProvider = new ServiceProvider(serviceProvider); } }
/// <summary> /// Get export /// </summary> internal static T GetExport <T>(IVsHierarchy hier) { System.IServiceProvider sp = new Microsoft.VisualStudio.Shell.ServiceProvider((OLE.Interop.IServiceProvider)hier.GetDTEProject().DTE); IComponentModel compMode = sp.GetService <IComponentModel, SComponentModel>(); return(compMode.DefaultExportProvider.GetExport <T>().Value); }
public static IVsProject GetSelectedProject() { IVsHierarchy hier = null; Microsoft.VisualStudio.Shell.ServiceProvider sp = new Microsoft.VisualStudio.Shell.ServiceProvider( Package.Instance.DTE as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); IVsMonitorSelection selectionMonitor = sp.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection; // // There isn't an open project. // if (selectionMonitor != null) { IntPtr ppHier; uint pitemid; IVsMultiItemSelect ppMIS; IntPtr ppSC; ErrorHandler.ThrowOnFailure(selectionMonitor.GetCurrentSelection(out ppHier, out pitemid, out ppMIS, out ppSC)); if (ppHier != IntPtr.Zero) { hier = (IVsHierarchy)Marshal.GetObjectForIUnknown(ppHier); Marshal.Release(ppHier); } if (ppSC != IntPtr.Zero) { Marshal.Release(ppSC); } } return(hier as IVsProject); }
public IronPythonEngineProvider(IOleServiceProvider serviceProvider) { if (null != serviceProvider) { this.serviceProvider = new ServiceProvider(serviceProvider); } }
protected void LaunchDebugTarget() { Microsoft.VisualStudio.Shell.ServiceProvider sp = new Microsoft.VisualStudio.Shell.ServiceProvider((IOleServiceProvider)Dte); IVsDebugger dbg = (IVsDebugger)sp.GetService(typeof(SVsShellDebugger)); VsDebugTargetInfo info = new VsDebugTargetInfo(); info.cbSize = (uint)Marshal.SizeOf(info); info.dlo = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; info.bstrExe = Moniker; info.bstrCurDir = @"C:\"; string connectionString = HierarchyAccessor.Connection.ConnectionSupport.ConnectionString + ";Allow User Variables=true;Allow Zero DateTime=true;"; if (connectionString.IndexOf("password", StringComparison.OrdinalIgnoreCase) == -1) { var connection = (MySqlConnection)HierarchyAccessor.Connection.GetLockedProviderObject(); try { var settings = (MySqlConnectionStringBuilder)connection.GetType().GetProperty("Settings", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(connection, null); connectionString += "password="******";Persist Security Info=true;"; } finally { HierarchyAccessor.Connection.UnlockProviderObject(); } } info.bstrArg = connectionString; info.bstrRemoteMachine = null; // Environment.MachineName; // debug locally info.fSendStdoutToOutputWindow = 0; // Let stdout stay with the application. info.clsidCustom = new Guid("{EEEE0740-10F7-4e5f-8BC4-1CC0AC9ED5B0}"); // Set the launching engine the sample engine guid info.grfLaunch = 0; IntPtr pInfo = Marshal.AllocCoTaskMem((int)info.cbSize); Marshal.StructureToPtr(info, pInfo, false); try { int result = dbg.LaunchDebugTargets(1, pInfo); if (result != 0 && result != VSConstants.E_ABORT) { throw new ApplicationException("COM error " + result); } } catch (Exception ex) { InfoDialog.ShowDialog(InfoDialogProperties.GetErrorDialogProperties("Debugger Error", ex.GetBaseException().Message)); } finally { if (pInfo != IntPtr.Zero) { Marshal.FreeCoTaskMem(pInfo); } } }
/// <summary> /// Runs the custom tool of a project item. /// </summary> /// <param name="project">IVsProject</param> /// <param name="itemId">item id</param> public static void RunCustomToolOfItem(this IVsProject project, uint itemId) { Microsoft.VisualStudio.OLE.Interop.IServiceProvider ppSP; project.GetItemContext(itemId, out ppSP); Microsoft.VisualStudio.Shell.ServiceProvider itemContextService = new Microsoft.VisualStudio.Shell.ServiceProvider(ppSP); EnvDTE.ProjectItem templateItem = (EnvDTE.ProjectItem)itemContextService.GetService(typeof(EnvDTE.ProjectItem)); VSLangProj.VSProjectItem vsProjectItem = templateItem.Object as VSLangProj.VSProjectItem; vsProjectItem.RunCustomTool(); }
void IObjectWithSite.SetSite(object pUnkSite) { _site = pUnkSite; _serviceProvider = _site == null ? null : new Microsoft.VisualStudio.Shell.ServiceProvider(_site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); _codeDomProvider = null; }
private void Dispose(bool dispose) { if (dispose) { if (_serviceProvider != null) { _serviceProvider.Dispose(); _serviceProvider = null; } } }
public void TestJoinableTaskFactoryObtainedFromEnvironment() { var taskSchedulerServiceObject = ServiceProvider.GetService(typeof(SVsTaskSchedulerService)); Assert.NotNull(taskSchedulerServiceObject); var taskSchedulerService = taskSchedulerServiceObject as IVsTaskSchedulerService2; Assert.NotNull(taskSchedulerService); Assert.Same(JoinableTaskContext, taskSchedulerService.GetAsyncTaskContext()); }
private ITypeResolutionService GetResolutionService(EnvDTE.Project project, Microsoft.VisualStudio.Shell.ServiceProvider provider) { var typeService = (DynamicTypeService)provider.GetService(typeof(DynamicTypeService)); Debug.Assert(typeService != null, "No dynamic type service registered."); IVsSolution sln = (IVsSolution)provider.GetService(typeof(IVsSolution)); IVsHierarchy hier; sln.GetProjectOfUniqueName(project.UniqueName, out hier); return(typeService.GetTypeResolutionService(hier)); }
internal static BindingSource LoadMySqlConnectionsFromServerExplorer(DTE dte) { Microsoft.VisualStudio.Shell.ServiceProvider sp = new Microsoft.VisualStudio.Shell.ServiceProvider((IOleServiceProvider)dte); IVsDataExplorerConnectionManager seConnectionsMgr = (IVsDataExplorerConnectionManager)sp.GetService(typeof(IVsDataExplorerConnectionManager).GUID); var mysqlDataExplorerConnections = new List <IVsDataExplorerConnection>(); if (seConnectionsMgr != null) { IDictionary <string, IVsDataExplorerConnection> serverExplorerconnections = seConnectionsMgr.Connections; foreach (var connection in serverExplorerconnections) { if (GuidList.Provider.Equals(connection.Value.Provider)) { mysqlDataExplorerConnections.Add(connection.Value); } } } var connections = new BindingSource(); connections.DataSource = new List <MySqlServerExplorerConnection>(); foreach (IVsDataExplorerConnection con in mysqlDataExplorerConnections) { // get complete connections try { var activeConnection = (MySqlConnection)(con.Connection).GetLockedProviderObject(); if (activeConnection != null) { var csb = (MySqlConnectionStringBuilder)activeConnection.GetType().GetProperty("Settings", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(activeConnection, null); if (csb != null) { connections.Add(new MySqlServerExplorerConnection { DisplayName = con.DisplayName, ConnectionString = csb.ConnectionString }); } } } catch { // ignored } finally { (con.Connection).UnlockProviderObject(); } } return(connections); }
public void TestJoinableTaskFactoryProvidedByTest() { var taskSchedulerServiceObject = ServiceProvider.GetService(typeof(SVsTaskSchedulerService)); Assert.NotNull(taskSchedulerServiceObject); var taskSchedulerService = taskSchedulerServiceObject as IVsTaskSchedulerService; Assert.NotNull(taskSchedulerService); var taskSchedulerService2 = taskSchedulerServiceObject as IVsTaskSchedulerService2; Assert.Null(taskSchedulerService2); Assert.NotNull(JoinableTaskContext); }
public static RamlScaffoldServiceBase GetRamlScaffoldService(Microsoft.VisualStudio.Shell.ServiceProvider serviceProvider) { var dte = serviceProvider.GetService(typeof(SDTE)) as DTE; var proj = VisualStudioAutomationHelper.GetActiveProject(dte); RamlScaffoldServiceBase service; if (VisualStudioAutomationHelper.IsANetCoreProject(proj)) { service = new RamlScaffoldServiceAspNetCore(new T4Service(serviceProvider), serviceProvider); } else { service = new RamlScaffoldServiceWebApi(new T4Service(serviceProvider), serviceProvider); } return(service); }
public static UnitTestsScaffoldServiceBase GetScaffoldService(Microsoft.VisualStudio.Shell.ServiceProvider serviceProvider) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); var dte = serviceProvider.GetService(typeof(SDTE)) as DTE; var proj = VisualStudioAutomationHelper.GetActiveProject(dte); UnitTestsScaffoldServiceBase service; if (VisualStudioAutomationHelper.IsANetCoreProject(proj)) { service = new UnitTestsScaffoldServiceAspNetCore(new T4Service(serviceProvider), serviceProvider); } else { service = new UnitTestsScaffoldServiceAspNetWebApi(new T4Service(serviceProvider), serviceProvider); } return(service); }
/// <summary> /// Returns an IVsTextView for the given file path, if the given file is open in Visual Studio. /// </summary> /// <param name="filePath">Full Path of the file you are looking for.</param> /// <returns>The IVsTextView for this file, if it is open, null otherwise.</returns> internal static Microsoft.VisualStudio.TextManager.Interop.IVsTextView GetIVsTextView(DTE dte, string filePath) { Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte; Microsoft.VisualStudio.Shell.ServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(sp); Microsoft.VisualStudio.Shell.Interop.IVsUIHierarchy uiHierarchy; uint itemID; Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame windowFrame; Microsoft.VisualStudio.Text.Editor.IWpfTextView wpfTextView = null; if (Microsoft.VisualStudio.Shell.VsShellUtilities.IsDocumentOpen(serviceProvider, filePath, Guid.Empty, out uiHierarchy, out itemID, out windowFrame)) { // Get the IVsTextView from the windowFrame. return(Microsoft.VisualStudio.Shell.VsShellUtilities.GetTextView(windowFrame)); } return(null); }
// Get IVsTextView from filepath internal static Microsoft.VisualStudio.TextManager.Interop.IVsTextView IVsTextView_FromFilePath_Get(string filePath) { var dte2 = (EnvDTE80.DTE2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(Microsoft.VisualStudio.Shell.Interop.SDTE)); Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte2; Microsoft.VisualStudio.Shell.ServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(sp); Microsoft.VisualStudio.Shell.Interop.IVsUIHierarchy uiHierarchy; uint itemID; Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame windowFrame; Microsoft.VisualStudio.Text.Editor.IWpfTextView wpfTextView = null; if (Microsoft.VisualStudio.Shell.VsShellUtilities.IsDocumentOpen(serviceProvider, filePath, Guid.Empty, out uiHierarchy, out itemID, out windowFrame)) { return(Microsoft.VisualStudio.Shell.VsShellUtilities.GetTextView(windowFrame)); } return(null); }
public static EnvDTE.Project GetSelectedProject() { Microsoft.VisualStudio.Shell.ServiceProvider sp = new Microsoft.VisualStudio.Shell.ServiceProvider( Package.Instance.DTE as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); IVsMonitorSelection selectionMonitor = sp.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection; // // There isn't an open project. // if (selectionMonitor == null) { return(null); } EnvDTE.Project project = null; IntPtr ppHier; uint pitemid; IVsMultiItemSelect ppMIS; IntPtr ppSC; if (ErrorHandler.Failed(selectionMonitor.GetCurrentSelection(out ppHier, out pitemid, out ppMIS, out ppSC))) { return(null); } if (ppHier != IntPtr.Zero) { IVsHierarchy hier = (IVsHierarchy)Marshal.GetObjectForIUnknown(ppHier); Marshal.Release(ppHier); object obj; hier.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out obj); if (obj != null) { project = obj as EnvDTE.Project; } } if (ppSC != IntPtr.Zero) { Marshal.Release(ppSC); } return(project); }
public static EnvDTE.Project GetSelectedProject() { Microsoft.VisualStudio.Shell.ServiceProvider sp = new Microsoft.VisualStudio.Shell.ServiceProvider( Package.Instance.DTE as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); IVsMonitorSelection selectionMonitor = sp.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection; // // There isn't an open project. // if(selectionMonitor == null) { return null; } EnvDTE.Project project = null; IntPtr ppHier; uint pitemid; IVsMultiItemSelect ppMIS; IntPtr ppSC; if (ErrorHandler.Failed(selectionMonitor.GetCurrentSelection(out ppHier, out pitemid, out ppMIS, out ppSC))) { return null; } if (ppHier != IntPtr.Zero) { IVsHierarchy hier = (IVsHierarchy)Marshal.GetObjectForIUnknown(ppHier); Marshal.Release(ppHier); object obj; hier.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out obj); if (obj != null) { project = obj as EnvDTE.Project; } } if (ppSC != IntPtr.Zero) { Marshal.Release(ppSC); } return project; }
private void TestSPService() { //<Snippet1> Microsoft.VisualStudio.Shell.ServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider( _applicationObject as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); Microsoft.VisualStudio.SharePoint.ISharePointProjectService projectService = serviceProvider.GetService(typeof(Microsoft.VisualStudio.SharePoint.ISharePointProjectService)) as Microsoft.VisualStudio.SharePoint.ISharePointProjectService; if (projectService != null) { projectService.Logger.WriteLine("This message was written by using the SharePoint project service.", Microsoft.VisualStudio.SharePoint.LogCategory.Message); } //</Snippet1> projectService.ProjectAdded += new EventHandler <Microsoft.VisualStudio.SharePoint.SharePointProjectEventArgs>( projectService_ProjectAdded); }
public virtual int SetSite(IOleServiceProvider psp) { _serviceProvider = new ServiceProvider(psp); return(VSConstants.S_OK); }
/// <summary> /// Création d'un label lors de la publication /// </summary> /// <param name="model"></param> private void CreateLabel(CandleModel model, string modelFileName) { if (model == null || modelFileName == null) { return; } try { DTE dte = GetService <DTE>(); string solutionFolder = Path.GetDirectoryName(modelFileName); // Récupère les caractèristiques du workspace contenant le fichier contenant le modèle if (Workstation.Current == null) { throw new Exception("TFS not installed"); } WorkspaceInfo wi = Workstation.Current.GetLocalWorkspaceInfo(solutionFolder); if (wi == null) { LogError("The current solution is not in a Team System workspace"); return; } // Récupèration du server TFS à partir des infos du workspace TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(wi.ServerUri.AbsoluteUri); // Création d'un label sur la solution VersionControlServer vcs = tfs.GetService(typeof(VersionControlServer)) as VersionControlServer; vcs.NonFatalError += new ExceptionEventHandler(vcs_NonFatalError); // On prend tous les fichiers de la solution ItemSpec itemSpec = new ItemSpec(solutionFolder, RecursionType.Full); LabelItemSpec labelItemSpec = new LabelItemSpec(itemSpec, VersionSpec.Latest, false); string changeSet = "-"; // Calcul du nom du label string labelName = String.Format(labelNameFormat, DateTime.Now, wi.OwnerName, wi.Computer, model.Version, model.Version.Revision, changeSet); // Calcul du commentaire string labelComment = String.Format(labelCommentFormat, DateTime.Now, wi.OwnerName, wi.Computer, model.Version, model.Version.Revision, changeSet); //Checkin if (forceCheckin) { Workspace ws = wi.GetWorkspace(tfs); PendingChange[] pendingChanges = ws.GetPendingChanges(new ItemSpec[] { itemSpec }, false); if (pendingChanges.Length > 0) { changeSet = ws.CheckIn(pendingChanges, labelComment).ToString(); // Mise à jour de l'explorateur de solution (icones) Microsoft.VisualStudio.Shell.ServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte); IVersionControlProvider versionControlProvider = (IVersionControlProvider)serviceProvider.GetService(typeof(IVersionControlProvider)); if (versionControlProvider != null) { versionControlProvider.RefreshStatus(); } // On intègre le changeset dans le commentaire labelName = String.Format(labelNameFormat, DateTime.Now, wi.OwnerName, wi.Computer, model.Version, model.Version.Revision, changeSet); labelComment = String.Format(labelCommentFormat, DateTime.Now, wi.OwnerName, wi.Computer, model.Version, model.Version.Revision, changeSet); } } string scope; string label; LabelSpec.Parse(labelName, null, false, out label, out scope); VersionControlLabel vcl = new VersionControlLabel(vcs, label, null, scope, labelComment); // Et on applique le label. LabelResult[] results = vcs.CreateLabel(vcl, new LabelItemSpec[] { labelItemSpec }, childOption); } catch (Exception ex) { LogError(ex); nbErrors++; } if (nbErrors > 0 && stopOnError) { throw new PublishingException(); } }
protected void LaunchDebugTarget() { Microsoft.VisualStudio.Shell.ServiceProvider sp = new Microsoft.VisualStudio.Shell.ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)Dte); IVsDebugger dbg = (IVsDebugger)sp.GetService(typeof(SVsShellDebugger)); VsDebugTargetInfo info = new VsDebugTargetInfo(); info.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(info); info.dlo = Microsoft.VisualStudio.Shell.Interop.DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; info.bstrExe = Moniker; info.bstrCurDir = @"C:\"; string connectionString = HierarchyAccessor.Connection.ConnectionSupport.ConnectionString + ";Allow User Variables=true;Allow Zero DateTime=true;"; if (connectionString.IndexOf("password", StringComparison.OrdinalIgnoreCase) == -1) { MySql.Data.MySqlClient.MySqlConnection connection = ((MySql.Data.MySqlClient.MySqlConnection)HierarchyAccessor.Connection.GetLockedProviderObject()); try { MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings = (MySql.Data.MySqlClient.MySqlConnectionStringBuilder)connection.GetType().GetProperty("Settings", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(connection, null); connectionString += "password="******";Persist Security Info=true;"; } finally { HierarchyAccessor.Connection.UnlockProviderObject(); } } info.bstrArg = connectionString; info.bstrRemoteMachine = null; // Environment.MachineName; // debug locally info.fSendStdoutToOutputWindow = 0; // Let stdout stay with the application. info.clsidCustom = new Guid("{EEEE0740-10F7-4e5f-8BC4-1CC0AC9ED5B0}"); // Set the launching engine the sample engine guid info.grfLaunch = 0; IntPtr pInfo = System.Runtime.InteropServices.Marshal.AllocCoTaskMem((int)info.cbSize); System.Runtime.InteropServices.Marshal.StructureToPtr(info, pInfo, false); try { int result = dbg.LaunchDebugTargets(1, pInfo); if (result != 0 && result != VSConstants.E_ABORT) throw new ApplicationException("COM error " + result); } catch (Exception ex) { MessageBox.Show(ex.GetBaseException().Message, "Debugger Error"); } finally { if (pInfo != IntPtr.Zero) { System.Runtime.InteropServices.Marshal.FreeCoTaskMem(pInfo); } } }
void IObjectWithSite.SetSite(object pUnkSite) { _site = pUnkSite; _serviceProvider = _site == null ? null : new Microsoft.VisualStudio.Shell.ServiceProvider(_site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); _codeDomProvider = null; }
private void LoadWindow(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; try { // ctlProgID - the ProgID for your user control. asmPath - the path to your user control DLL. guidStr - a unique GUID for the user control. string ctlProgID, asmPath, guidStr; // Variables for the new tool window that will hold // your user control. EnvDTE80.Windows2 toolWins; EnvDTE.Window toolWin; object objTemp = null; ctlProgID = "Slam.Visualizers"; // Replace the <Path to VS Project> with the path to // the folder where you created the WindowsCotrolLibrary. // Remove the line returns from the path before // running the add-in. asmPath = @"C:\Users\Patrick\Documents\GitHub\bin\Slam.Visualizers.exe"; guidStr = "{9ED54F84-A89D-4fcd-A854-44251E922109}"; toolWins = (Windows2)_applicationObject.Windows; // Create the new tool window, adding your user control. toolWin = toolWins.CreateToolWindow2(_addInInstance, asmPath, ctlProgID, "Slam Visualizers", guidStr, ref objTemp); // The tool window must be visible before you do anything // with it, or you will get an error. if (toolWin != null) { toolWin.Visible = true; } toolWin.Height = 500; toolWin.Width = 400; // Get the service provider on the object Microsoft.VisualStudio.Shell.ServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(this._applicationObject as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); // Get the shell service var vsUIShell = (IVsUIShell)serviceProvider.GetService(typeof(SVsUIShell)); Guid slotGuid = new Guid("63ed935d-eac2-4b8f-9208-f28f48d49f6b"); // Find the associated window frame on this toolwindow IVsWindowFrame wndFrame; vsUIShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fFrameOnly, ref slotGuid, out wndFrame); // Set the text on the window tab name wndFrame.SetProperty((int)__VSFPROPID.VSFPROPID_Caption, "Slam"); } catch (Exception ex) { throw ex; } }
internal static void SetProjectPropertyGroupValue(Project project, string propertyName, string newValue) { IVsSolution solution = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution; DTE dte = project.DTE; //IServiceProvider sp = dte as IServiceProvider; IServiceProvider sp = new Microsoft.VisualStudio.Shell.ServiceProvider(project.DTE as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); string uniqueName = project.UniqueName; IVsHierarchy hierarchy; hierarchy = DteHelper.GetVsHierarchy(sp, project); IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage; int hr = buildPropertyStorage.SetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, newValue); }
private bool Start () { AddBindingPaths (); // This environment variable is used by the VsRemoveRunner to set up the right // server channel named pipe, which is later used by the test runner to execute // tests in the VS app domain. Environment.SetEnvironmentVariable (Constants.PipeNameEnvironmentVariable, pipeName); Process = new Process { StartInfo = { FileName = devEnvPath, Arguments = string.IsNullOrEmpty (rootSuffix) ? "" : "/RootSuffix " + rootSuffix, UseShellExecute = false, WorkingDirectory = Directory.GetCurrentDirectory (), }, }; Process.Start (); // This forces us to wait until VS is fully started. var dte = RunningObjects.GetDTE (visualStudioVersion, Process.Id, TimeSpan.FromSeconds (120)); if (dte == null) return false; var services = new Microsoft.VisualStudio.Shell.ServiceProvider ((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte); IVsShell shell; while ((shell = (IVsShell)services.GetService (typeof (SVsShell))) == null) { System.Threading.Thread.Sleep (100); } object zombie; while ((int?)(zombie = shell.GetProperty ((int)__VSSPROPID.VSSPROPID_Zombie, out zombie)) != 0) { System.Threading.Thread.Sleep (100); } if (Debugger.IsAttached) { // When attached via TD.NET, there will be an environment variable named DTE_MainWindow=2296172 var mainWindow = Environment.GetEnvironmentVariable ("DTE_MainWindow"); if (!string.IsNullOrEmpty (mainWindow)) { var mainHWnd = int.Parse (mainWindow); var mainDte = GetAllDtes ().FirstOrDefault (x => x.MainWindow.HWnd == mainHWnd); if (mainDte != null) { var startedVs = mainDte.Debugger.LocalProcesses.OfType<EnvDTE.Process> ().FirstOrDefault (x => x.ProcessID == Process.Id); if (startedVs != null) startedVs.Attach (); } } } try { Injector.Launch (Process.MainWindowHandle, this.GetType ().Assembly.Location, typeof (VsStartup).FullName, "Start"); } catch (Exception) { return false; } return true; }
/// <summary> /// Returns a Project based on its GUID /// </summary> public static Project FindProjectByGuid(EnvDTE.Solution solution, Guid projectGuid) { Microsoft.VisualStudio.Shell.ServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(solution.DTE as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); IVsSolution vsSolution = (IVsSolution)serviceProvider.GetService(typeof(SVsSolution)); IVsHierarchy hierarchy; vsSolution.GetProjectOfGuid(ref projectGuid, out hierarchy); object prjObject = null; if(hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out prjObject) >= 0) { return (Project)prjObject; } else { throw new ArgumentException("Hierarchy is not a project."); } }
public IronPythonEngineProvider(IOleServiceProvider serviceProvider) { if (null != serviceProvider) { this.serviceProvider = new ServiceProvider(serviceProvider); } }
// Get IVsTextView from filepath internal static Microsoft.VisualStudio.TextManager.Interop.IVsTextView IVsTextView_FromFilePath_Get(string filePath) { var dte2 = (EnvDTE80.DTE2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(Microsoft.VisualStudio.Shell.Interop.SDTE)); Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte2; Microsoft.VisualStudio.Shell.ServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(sp); Microsoft.VisualStudio.Shell.Interop.IVsUIHierarchy uiHierarchy; uint itemID; Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame windowFrame; Microsoft.VisualStudio.Text.Editor.IWpfTextView wpfTextView = null; if (Microsoft.VisualStudio.Shell.VsShellUtilities.IsDocumentOpen(serviceProvider, filePath, Guid.Empty, out uiHierarchy, out itemID, out windowFrame)) { return Microsoft.VisualStudio.Shell.VsShellUtilities.GetTextView(windowFrame); } return null; }
/// <summary> /// Returns solution projects. /// </summary> private void GetProjectsInternal(SolutionModel model, ProcessorFlags flags, CodeModelFilterFlags filter) { ThreadHelper.ThrowIfNotOnUIThread(); _log.LogMessage("Collecting solution projects", LOG_CATEGORY); var dte = _shellProjectService.GetDTE() as DTE; var serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(dte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); var solutionService = serviceProvider.GetService <IVsSolution, SVsSolution>(false); Guid guid = Guid.Empty; if (solutionService.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, ref guid, out IEnumHierarchies enumHierarchies) != VSConstants.S_OK) { return; } IVsHierarchy[] hierarchy = new IVsHierarchy[1]; List <Project> projects = new List <Project>(); while ((enumHierarchies.Next((uint)hierarchy.Length, hierarchy, out uint fetched) == VSConstants.S_OK) && (fetched == hierarchy.Length)) { if ((hierarchy.Length > 0) && (hierarchy[0] != null)) { IVsHierarchy projectHierarchy = hierarchy[0]; if ((projectHierarchy.GetProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ExtObject, out object project) == VSConstants.S_OK) && (project is Project dteProject) && _shellProjectService.IsProject(project)) { projects.Add(dteProject); } } } _log.LogMessage("Resolving solution name", LOG_CATEGORY); var solution = dte.Solution?.FileName; if (!string.IsNullOrEmpty(solution)) { solution = Path.GetFileNameWithoutExtension(solution); } model.SolutionName = solution; _log.LogMessage($"Processing {projects.Count} collected solution projects", LOG_CATEGORY); foreach (Project project in projects) { if (_shellProjectService.IsProjectLoadDeferred(project, out _)) { continue; } if (ProcessProject(project, model.Projects, flags, filter)) { ProcessProjectRecursively(project, model.Projects, flags, filter); } } model.Files = model.Projects.SelectMany(p => p.Files).ToList(); if (flags.HasFlag(ProcessorFlags.GroupLinkedFiles)) { // Get all grouped, ie duplicate, files, keep the first code file and remove the rest var groupedFiles = model.Files.GroupBy(f => f.FileNameWithPath).Where(g => g.Count() > 1).Select(g => g); foreach (var group in groupedFiles) { var file = group.FirstOrDefault(f => f.Project.Language.SupportsCompileBuildAction && _shellProjectService.CompileBuildAction(f.ProjectItem)); if (file != null) { group.ForEach(f => { if (f != file) { model.Files.Remove(f); f.Project.Files.Remove(f); AddProjectName(file, f.ProjectName); } }); } } } _log.LogMessage($"Processed {model.Projects.Count} qualified solution projects", LOG_CATEGORY); }
public static System.IServiceProvider GetServiceProvider(EnvDTE.Project project) { System.IServiceProvider sp = new Microsoft.VisualStudio.Shell.ServiceProvider(project.DTE as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); return(sp); }
public virtual int SetSite(IOleServiceProvider psp) { _serviceProvider = new ServiceProvider(psp); return VSConstants.S_OK; }
internal static void ShowNewConnectionDialog(TextBox connectionStringTextBox, DTE dte, ComboBox cmbConnections, bool addSeConnection) { if (dte == null) { throw new ArgumentNullException("dte"); } try { var settings = connectionStringTextBox.Tag != null ? new MySqlConnectionStringBuilder(connectionStringTextBox.Tag.ToString()) : new MySqlConnectionStringBuilder(); var dlg = connectionStringTextBox.Tag == null ? new ConnectDialog() : new ConnectDialog(settings); DialogResult res = dlg.ShowDialog(); if (res != DialogResult.OK) { return; } if ((MySqlConnection)dlg.Connection == null) { return; } var csb = (MySqlConnectionStringBuilder)((MySqlConnection)dlg.Connection).GetType().GetProperty("Settings", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(((MySqlConnection)dlg.Connection), null); if (csb == null) { return; } //make sure we don't have already the same connection if (cmbConnections.FindString(string.Format("{0}({1})", csb.Server, csb.Database)) < 0) { connectionStringTextBox.Tag = csb.ConnectionString; if (!string.IsNullOrEmpty(connectionStringTextBox.Tag.ToString()) && addSeConnection) { // adding connection to server explorer connections Microsoft.VisualStudio.Shell.ServiceProvider sp = new Microsoft.VisualStudio.Shell.ServiceProvider((IOleServiceProvider)dte); IVsDataExplorerConnectionManager seConnectionsMgr = (IVsDataExplorerConnectionManager)sp.GetService(typeof(IVsDataExplorerConnectionManager).GUID); seConnectionsMgr.AddConnection(string.Format("{0}({1})", csb.Server, csb.Database), GuidList.Provider, connectionStringTextBox.Tag.ToString(), false); var connections = (List <MySqlServerExplorerConnection>)cmbConnections.DataSource; connections.Add(new MySqlServerExplorerConnection { DisplayName = string.Format("{0}({1})", csb.Server, csb.Database), ConnectionString = csb.ConnectionString }); cmbConnections.DataSource = null; cmbConnections.DataSource = connections; cmbConnections.ValueMember = "ConnectionString"; cmbConnections.DisplayMember = "DisplayName"; } } cmbConnections.Text = string.Format("{0}({1})", csb.Server, csb.Database); connectionStringTextBox.Text = MaskPassword(csb.ConnectionString); connectionStringTextBox.Tag = csb.ConnectionString; } catch (Exception ex) { MySqlSourceTrace.WriteAppErrorToLog(ex, null, "The connection string is not valid.", true); } }
internal static object GetProjectPropertyGroupValue(Project project, string propertyName, string defaultValue) { IVsSolution solution = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution; DTE dte = project.DTE; //IServiceProvider sp = dte as IServiceProvider; IServiceProvider sp = new Microsoft.VisualStudio.Shell.ServiceProvider(project.DTE as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); string uniqueName = project.UniqueName; IVsHierarchy hierarchy; hierarchy = DteHelper.GetVsHierarchy(sp, project); //solution.GetProjectOfUniqueName(uniqueName, out hierarchy); IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage; string value = null; int hr = buildPropertyStorage.GetPropertyValue(propertyName, null, (uint)_PersistStorageType.PST_PROJECT_FILE, out value); if (value == null) { value = defaultValue; } return value; }