public override void TestInitialize() { base.TestInitialize(); this.OpenSolution("SampleSolution\\SampleSolution.sln"); this.solution = base.ServiceLocator.GetInstance <ISolutionExplorer>().Solution; }
public override void TestInitialize() { base.TestInitialize(); this.OpenSolution("SampleSolution\\SampleSolution.sln"); this.solution = base.ServiceLocator.GetInstance<ISolutionExplorer>().Solution; }
/// <summary> /// Finds all the project nodes in the solution. /// </summary> /// <param name="solution">The solution to traverse.</param> /// <returns>All project nodes that were found.</returns> public static IEnumerable <IProjectNode> FindProjects(this ISolutionNode solution) { var visitor = new ProjectsVisitor(); solution.Accept(visitor); return(visitor.Projects); }
/// <summary> /// Finds all projects in the solution matching the given predicate. /// </summary> /// <param name="solution">The solution to traverse.</param> /// <param name="predicate">Predicate used to match projects.</param> /// <returns>All project nodes matching the given predicate that were found.</returns> public static IEnumerable <IProjectNode> FindProjects(this ISolutionNode solution, Func <IProjectNode, bool> predicate) { var visitor = new FilteringProjectsVisitor(predicate); solution.Accept(visitor); return(visitor.Projects); }
/// <summary> /// Finds the first project in the solution matching the given predicate. /// </summary> /// <param name="solution">The solution to traverse.</param> /// <param name="predicate">Predicate used to match projects.</param> /// <returns>The first project matching the given predicate, or <see langword="null"/>.</returns> public static IProjectNode FindProject(this ISolutionNode solution, Func <IProjectNode, bool> predicate) { var visitor = new FilteringProjectsVisitor(predicate, true); solution.Accept(visitor); return(visitor.Projects.FirstOrDefault()); }
public SolutionFixture(string solutionFile) { if (!Path.IsPathRooted(solutionFile)) { var rootedFile = Path.Combine(Path.GetDirectoryName(GetType().Assembly.ManifestModule.FullyQualifiedName), solutionFile); if (!File.Exists(rootedFile)) { rootedFile = Path.Combine(baseDirectory, solutionFile); var currentDir = new DirectoryInfo(Directory.GetCurrentDirectory()); while (!File.Exists(rootedFile) && currentDir != null) { rootedFile = Path.Combine(currentDir.FullName, solutionFile); currentDir = currentDir.Parent; } } solutionFile = rootedFile; } if (!File.Exists(solutionFile)) { throw new FileNotFoundException("Could not find solution file " + solutionFile, solutionFile); } try { var dte = GlobalServices.GetService <DTE>(); if (!dte.Solution.IsOpen || !dte.Solution.FullName.Equals(solutionFile, StringComparison.OrdinalIgnoreCase)) { // Ensure no .suo is loaded, since that would dirty the state across runs. var suoFile = Path.ChangeExtension(solutionFile, ".suo"); if (File.Exists(suoFile)) { Try(() => File.Delete(suoFile)); } var sdfFile = Path.ChangeExtension(solutionFile, ".sdf"); if (File.Exists(sdfFile)) { Try(() => File.Delete(sdfFile)); } var vsDir = Path.Combine(Path.GetDirectoryName(solutionFile), ".vs"); if (Directory.Exists(vsDir)) { Try(() => Directory.Delete(vsDir, true)); } dte.Solution.Open(solutionFile); GlobalServices.GetService <SVsSolution, IVsSolution4> () .EnsureSolutionIsLoaded((uint)(__VSBSLFLAGS.VSBSLFLAGS_LoadAllPendingProjects | __VSBSLFLAGS.VSBSLFLAGS_LoadBuildDependencies)); } } catch (Exception ex) { throw new ArgumentException("Failed to open and access solution: " + solutionFile, ex); } solution = GlobalServices.GetService <SComponentModel, IComponentModel> ().GetService <ISolutionExplorer> ().Solution; }
public SolutionNodeSpec () { var components = GlobalServices.GetService<SComponentModel, IComponentModel>(); var factory = components.GetService<ISolutionExplorerNodeFactory> (); var adapter = components.GetService<IAdapterService> (); var manager = components.DefaultExportProvider.GetExportedValue<IVsHierarchyItemManager>(ContractNames.Interop.IVsHierarchyItemManager); var selection = components.GetService<IVsSolutionSelection>(); var solutionExplorer = components.DefaultExportProvider.GetExport<IVsUIHierarchyWindow>(ContractNames.Interop.SolutionExplorerWindow); var item = manager.GetHierarchyItem(GlobalServices.GetService<SVsSolution, IVsHierarchy>(), (uint)VSConstants.VSITEMID.Root); solution = new SolutionNode (GlobalServices.Instance, item, factory, adapter, selection, solutionExplorer); }
public void how_to_convert_IVsSolution_ISolutionNode() { // Say you have an IVsSolution: var vsSolution = (IVsSolution)ServiceProvider.GetService(typeof(SVsSolution)); ISolutionNode solutionNode = vsSolution.Adapt().AsSolutionNode(); Assert.IsNotNull(solutionNode); // Use the solution node to get the active project, for example: IProjectNode activeProject = solutionNode.ActiveProject; }
public SolutionNodeSpec() { var components = GlobalServices.GetService <SComponentModel, IComponentModel>(); var factory = components.GetService <ISolutionExplorerNodeFactory> (); var adapter = components.GetService <IAdapterService> (); var manager = components.DefaultExportProvider.GetExportedValue <IVsHierarchyItemManager>(ContractNames.Interop.IVsHierarchyItemManager); var selection = components.GetService <IVsSolutionSelection>(); var solutionExplorer = components.DefaultExportProvider.GetExport <IVsUIHierarchyWindow>(ContractNames.Interop.SolutionExplorerWindow); var item = manager.GetHierarchyItem(GlobalServices.GetService <SVsSolution, IVsHierarchy>(), (uint)VSConstants.VSITEMID.Root); solution = new SolutionNode(GlobalServices.Instance, item, factory, adapter, selection, solutionExplorer); }
public void how_to_convert_DTE_Solution_to_ISolutionNode() { // Say you have a DTE Solution: EnvDTE.Solution dteSolution = Dte.Solution; ISolutionNode solutionNode = dteSolution.Adapt().AsSolutionNode(); Assert.IsNotNull(solutionNode); // Use the solution node to get the active project, for example: IProjectNode activeProject = solutionNode.ActiveProject; }
/// <summary> /// Visists the given visitor with the specified solution. /// </summary> public static bool Accept(ISolutionNode solution, ISolutionVisitor visitor) { if (visitor.VisitEnter(solution)) { foreach (var node in solution.Nodes) { if (!node.Accept(visitor)) break; } } return visitor.VisitLeave(solution); }
public SolutionNodeSpec() { var components = GlobalServices.GetService <SComponentModel, IComponentModel>(); var factory = components.GetService <ISolutionExplorerNodeFactory>(); var adapter = components.GetService <IAdapterService>(); var manager = components.DefaultExportProvider.GetExportedValue <IVsHierarchyItemManager>(ContractNames.Interop.IVsHierarchyItemManager); var selection = components.GetService <IVsSolutionSelection>(); var solutionExplorer = components.DefaultExportProvider.GetExport <IVsUIHierarchyWindow>(ContractNames.Interop.SolutionExplorerWindow); var item = manager.GetHierarchyItem(GlobalServices.GetService <SVsSolution, IVsHierarchy>(), (uint)VSConstants.VSITEMID.Root); #pragma warning disable VSSDK005 // Avoid instantiating JoinableTaskContext solution = new SolutionNode(GlobalServices.Instance, item, factory, adapter, selection, JoinableLazy.Create(() => solutionExplorer.Value, taskFactory: new JoinableTaskContext().Factory)); #pragma warning restore VSSDK005 // Avoid instantiating JoinableTaskContext }
/// <summary> /// Visists the given visitor with the specified solution. /// </summary> public static bool Accept(ISolutionNode solution, ISolutionVisitor visitor) { if (visitor.VisitEnter(solution)) { foreach (var node in solution.Nodes) { if (!node.Accept(visitor)) { break; } } } return(visitor.VisitLeave(solution)); }
public SolutionFixture (string solutionFile) { if (!Path.IsPathRooted (solutionFile)) { var rootedFile = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.ManifestModule.FullyQualifiedName), solutionFile); if (!File.Exists (rootedFile)) { rootedFile = Path.Combine (baseDirectory, solutionFile); var currentDir = new DirectoryInfo(Directory.GetCurrentDirectory()); while (!File.Exists (rootedFile) && currentDir != null) { rootedFile = Path.Combine (currentDir.FullName, solutionFile); currentDir = currentDir.Parent; } } solutionFile = rootedFile; } if (!File.Exists (solutionFile)) throw new FileNotFoundException ("Could not find solution file " + solutionFile, solutionFile); try { var dte = GlobalServices.GetService<DTE>(); if (!dte.Solution.IsOpen || !dte.Solution.FullName.Equals (solutionFile, StringComparison.OrdinalIgnoreCase)) { // Ensure no .suo is loaded, since that would dirty the state across runs. var suoFile = Path.ChangeExtension(solutionFile, ".suo"); if (File.Exists (suoFile)) Try (() => File.Delete (suoFile)); var sdfFile = Path.ChangeExtension(solutionFile, ".sdf"); if (File.Exists (sdfFile)) Try (() => File.Delete (sdfFile)); var vsDir = Path.Combine(Path.GetDirectoryName(solutionFile), ".vs"); if (Directory.Exists (vsDir)) Try (() => Directory.Delete (vsDir, true)); dte.Solution.Open (solutionFile); GlobalServices.GetService<SVsSolution, IVsSolution4> () .EnsureSolutionIsLoaded ((uint)(__VSBSLFLAGS.VSBSLFLAGS_LoadAllPendingProjects | __VSBSLFLAGS.VSBSLFLAGS_LoadBuildDependencies)); } } catch (Exception ex) { throw new ArgumentException ("Failed to open and access solution: " + solutionFile, ex); } solution = GlobalServices.GetService<SComponentModel, IComponentModel> ().GetService<ISolutionExplorer> ().Solution; }
/// <summary> /// Starts a build of the solution. /// </summary> public static Task <bool> Build(this ISolutionNode solution) { var sln = solution.As <EnvDTE.Solution>(); if (sln == null) { throw new ArgumentException(Strings.ISolutionNodeExtensions.BuildNotSupported); } return(System.Threading.Tasks.Task.Factory.StartNew <bool>(() => { var mre = new ManualResetEventSlim(); var events = sln.DTE.Events.BuildEvents; EnvDTE._dispBuildEvents_OnBuildDoneEventHandler done = (scope, action) => mre.Set(); events.OnBuildDone += done; try { // Let build run async. sln.SolutionBuild.Build(false); // Wait until it's done. mre.Wait(); // LastBuildInfo == # of projects that failed to build. return sln.SolutionBuild.LastBuildInfo == 0; } catch (Exception ex) { tracer.Error(ex, Strings.ISolutionNodeExtensions.BuildException); return false; } finally { // Cleanup handler. events.OnBuildDone -= done; } }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default)); }
/// <summary> /// Ends visiting the solution. /// </summary> /// <param name="solution">The solution being visited.</param> /// <returns> /// The result of the solution traversal operation. /// </returns> public virtual bool VisitLeave(ISolutionNode solution) { return(true); }
public bool VisitLeave(ISolutionNode solution) { throw new NotSupportedException(); }
public static IProjectNode UnfoldTemplate(this ISolutionNode solution, string templateId, string projectName, string language = "CSharp") => solution.AsProjectContainerNode().UnfoldTemplate(templateId, projectName, language);
/// <summary> /// Begins visiting the solution. /// </summary> /// <param name="solution">The solution being visited.</param> /// <returns> /// <see langword="true" /> if the solution child nodes should be visited; <see langword="false" /> otherwise. /// </returns> public virtual bool VisitEnter(ISolutionNode solution) { return(true); }
public bool VisitLeave (ISolutionNode solution) => true;
/// <summary> /// Ends visiting the solution. /// </summary> /// <param name="solution">The solution being visited.</param> /// <returns> /// The result of the solution traversal operation. /// </returns> public virtual bool VisitLeave(ISolutionNode solution) { return true; }
/// <summary> /// Adapts a <see cref="ISolutionNode"/> to an <see cref="IVsHierarchyItem"/>. /// </summary> /// <returns>The <see cref="IVsSolution"/> or <see langword="null"/> if conversion is not possible.</returns> public static IVsHierarchyItem AsVsHierarchyItem(this ISolutionNode solution) => solution.As <IVsHierarchyItem>();
/// <summary> /// Begins visiting the solution. /// </summary> /// <param name="solution">The solution being visited.</param> /// <returns> /// <see langword="true" /> if the solution child nodes should be visited; <see langword="false" /> otherwise. /// </returns> public virtual bool VisitEnter(ISolutionNode solution) => true;
/// <summary> /// Begins visiting the solution. /// </summary> /// <param name="solution">The solution being visited.</param> /// <returns> /// <see langword="true" /> if the solution child nodes should be visited; <see langword="false" /> otherwise. /// </returns> public virtual bool VisitEnter(ISolutionNode solution) { return true; }
public bool VisitEnter(ISolutionNode solution) => true;
/// <summary> /// Ends visiting the solution. /// </summary> /// <param name="solution">The solution being visited.</param> /// <returns> /// The result of the solution traversal operation. /// </returns> public virtual bool VisitLeave(ISolutionNode solution) => true;
/// <summary> /// Begins visiting the solution. /// </summary> /// <param name="solution">The solution being visited.</param> /// <returns> /// <see langword="true" /> if the solution child nodes should be visited; <see langword="false" /> otherwise. /// </returns> public virtual bool VisitEnter (ISolutionNode solution) => true;
/// <summary> /// Adapts a <see cref="ISolutionNode"/> to an <see cref="IVsSolution"/>. /// </summary> /// <returns>The <see cref="IVsSolution"/> or <see langword="null"/> if conversion is not possible.</returns> public static IVsSolution AsVsSolution(this ISolutionNode solution) => solution.As <IVsSolution>();
public virtual void Visit(ISolutionNode node) { DefaultVisit(node); }
/// <summary> /// Adapts a <see cref="ISolutionNode"/> to a DTE <see cref="Solution"/>. /// </summary> /// <returns>The DTE <see cref="Solution"/> or <see langword="null"/> if conversion is not possible.</returns> public static Solution AsSolution(this ISolutionNode solution) => solution.As <EnvDTE.Solution>();
/// <summary> /// Ends visiting the solution. /// </summary> /// <param name="solution">The solution being visited.</param> /// <returns> /// The result of the solution traversal operation. /// </returns> public virtual bool VisitLeave (ISolutionNode solution) => true;
/// <summary> /// Adapts a <see cref="ISolutionNode"/> to an <see cref="IVsHierarchy"/>. /// </summary> /// <returns>The <see cref="IVsSolution"/> or <see langword="null"/> if conversion is not possible.</returns> public static IVsHierarchy AsVsHierarchy(this ISolutionNode solution) => solution.As <IVsHierarchy>();
public ProjectContainerNode(ISolutionNode solutionNode) { this.solutionNode = solutionNode; this.hierarchyNode = new Lazy<IVsHierarchyItem>(() => solutionNode.AsVsHierarchyItem()); }
/// <summary> /// Finds all the project nodes in the solution. /// </summary> /// <param name="solution">The solution to traverse.</param> /// <returns>All project nodes that were found.</returns> public static IEnumerable <IProjectNode> FindProjects(this ISolutionNode solution) => solution.FindProjects(x => true);
public bool VisitEnter (ISolutionNode solution) => true;
internal static IProjectContainerNode AsProjectContainerNode(this ISolutionNode solution) => solution.As <IProjectContainerNode>();
public ProjectContainerNode(ISolutionNode solutionNode) { this.solutionNode = solutionNode; hierarchyNode = new Lazy <IVsHierarchyItem>(() => solutionNode.AsVsHierarchyItem()); }
public bool VisitLeave(ISolutionNode solution) => true;
/// <summary> /// Adapts the specified solution to supported target types. /// </summary> /// <param name="solution">The solution to adapt.</param> /// <returns>The entry point that exposes supported target types.</returns> public static IAdaptable <ISolutionNode> Adapt(this ISolutionNode solution) { return(new TreeNodeAdaptable <ISolutionNode>(solution)); }