public static void Open(this ISolution solution, string solutionFile) { Guard.NotNull(() => solution, solution); Guard.NotNullOrEmpty(() => solutionFile, solutionFile); solution.As <EnvDTE.Solution>().Open(solutionFile); }
public static void ShowSolutionExplorer(this ISolution solution) { Guard.NotNull(() => solution, solution); var vsSolution = solution.As <EnvDTE.Solution>(); if (vsSolution != null) { var dte = vsSolution.DTE; if (dte != null) { using (var provider = new ServiceProvider(dte as Ole.IServiceProvider)) { var service = provider.GetService <IVsUIShell>(); if (service != null) { var solutionExplorer = StandardToolWindows.ProjectExplorer; IVsWindowFrame frame; Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(service.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref solutionExplorer, out frame)); if (frame != null) { Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(frame.Show()); } } } } } }
public static void RemoveArtifactLinks(this IProductElement element, IUriReferenceService uriService, ISolution solution) { using (new MouseCursor(System.Windows.Input.Cursors.Wait)) { foreach (var referenceLink in element.References) { var item = default(IItemContainer); try { item = uriService.ResolveUri<IItemContainer>(new Uri(referenceLink.Value)); } catch { } if (item != null) { var physicalPath = item.PhysicalPath; if (item.Kind == ItemKind.Project) { solution.As<Solution>().Remove(item.As<Project>()); System.IO.Directory.Delete(Path.GetDirectoryName(physicalPath), true); } else if (item.Kind == ItemKind.Item) { item.As<ProjectItem>().Delete(); System.IO.File.Delete(physicalPath); } } } } }
public static void RemoveArtifactLinks(this IProductElement element, IUriReferenceService uriService, ISolution solution) { using (new MouseCursor(System.Windows.Input.Cursors.Wait)) { foreach (var referenceLink in element.References) { var item = default(IItemContainer); try { item = uriService.ResolveUri <IItemContainer>(new Uri(referenceLink.Value)); } catch { } if (item != null) { var physicalPath = item.PhysicalPath; if (item.Kind == ItemKind.Project) { solution.As <Solution>().Remove(item.As <Project>()); System.IO.Directory.Delete(Path.GetDirectoryName(physicalPath), true); } else if (item.Kind == ItemKind.Item) { item.As <ProjectItem>().Delete(); System.IO.File.Delete(physicalPath); } } } } }
public static void CreateInstance(this ISolution solution, string destination, string name) { Guard.NotNull(() => solution, solution); Guard.NotNullOrEmpty(() => destination, destination); Guard.NotNullOrEmpty(() => name, name); solution.As <EnvDTE.Solution>().Create(destination, name); }
public static void Close(this ISolution solution, bool saveFirst = true) { Guard.NotNull(() => solution, solution); if (solution.IsOpen) { solution.As <EnvDTE.Solution>().Close(saveFirst); } }
public static void SaveAs(this ISolution solution, string fileName) { Guard.NotNull(() => solution, solution); var dteSolution = solution.As <EnvDTE.Solution>(); if (dteSolution != null && !dteSolution.Saved) { dteSolution.SaveAs(fileName); } }
public static void RunCommand(this ISolution solution, string commandName) { Guard.NotNull(() => solution, solution); Guard.NotNull(() => commandName, commandName); var dteSolution = solution.As <EnvDTE.Solution>(); if (dteSolution != null) { dteSolution.DTE.ExecuteCommand(commandName); } }
/// <summary> /// Returns the path to the given installed template /// </summary> public static string GetTemplatePath(this ISolution solution, string name, string category) { Guard.NotNull(() => solution, solution); Guard.NotNullOrEmpty(() => name, name); Guard.NotNullOrEmpty(() => category, category); var solution2 = solution.As <EnvDTE80.Solution2>(); if (solution2 != null) { return(solution2.GetProjectTemplate(name, category)); } return(null); }
public static IEnumerable <IItemContainer> GetSelectedItems(this ISolution solution) { Guard.NotNull(() => solution, solution); if (solution.As <EnvDTE.Solution>() != null) { return(solution.GetSelection()); } else { return(solution .Traverse() .Concat(new[] { solution }) .Where(item => item.IsSelected)); } }
/// <summary> /// Gets the item that represents the file currently opened in an editor. /// </summary> /// <param name="solution">The solution to find the active editing document in.</param> /// <returns>The item or <see langword="null"/> if no item is currently being edited.</returns> public static IItem GetActiveEditorItem(this ISolution solution) { var vsSolution = solution.As <EnvDTE.Solution>(); if (vsSolution == null) { throw new NotSupportedException(Resources.VsItemContainerExtensions_ErrorNoSolution); } var activeDocument = vsSolution.DTE.ActiveDocument; if (activeDocument == null) { return(null); } return(solution.Traverse().OfType <IItem>().FirstOrDefault(i => i.PhysicalPath == activeDocument.FullName)); }
public static void CollapseAll(this ISolution solution, CollapseOptions options = CollapseOptions.All) { Guard.NotNull(() => solution, solution); EnvDTE.DTE dte = solution.As <EnvDTE.Solution>().DTE; dte.SuppressUI = true; try { var hier = dte.GetHierarchy(); hier.UIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>() .ForEach(item => { item.Collapse(options); }); } catch (COMException) { // Ignore exception } finally { dte.SuppressUI = false; } }
/// <summary> /// Selects the root of the solution /// </summary> /// <remarks> /// There is an issue in all versions of VS up to and including VS2008 SP1 /// that won't allow the expansion of a multi-project template unless the Solution node in the Solution explorer /// is selected. The code below works for any solution with less than 100,000 items /// </remarks> public static void SelectUp(this ISolution solution) { EnvDTE80.DTE2 dte2 = (EnvDTE80.DTE2)solution.As <EnvDTE.Solution>().DTE; dte2.ToolWindows.SolutionExplorer.SelectUp(vsUISelectionType.vsUISelectionTypeSelect, 99999); }