test/Misc/EFTools/TestInfrastructure/VS/DteExtensions.cs
/// <summary>
///     Select the given project in the solution explorer. If the project is null, it will select the solution.
/// </summary>
/// <param name="dte">dte instance</param>
/// <param name="project">the project to select</param>
Select the given project in the solution explorer. If the project is null, it will select the solution.
Select the given project in the solution explorer . If the project is null it will select the solution .
public static void SelectProject(this DTE dte, Project project)
        {
            Debug.Assert(dte != null, "dte != null");
            dte.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate();
            var uiItemFullName = string.Empty;
            if (project != null)
            {
                if (project.Kind == VenusProjectGuid)
                {
                    var tokens = project.Name.Split(new[] { '\\' });
                    uiItemFullName = tokens[tokens.Length - 2];
                }
                else
                {
                    uiItemFullName = project.Name;
                }
                uiItemFullName = "\\" + uiItemFullName;
                while (project.ParentProjectItem != null)
                {
                    uiItemFullName = "\\" + project.ParentProjectItem.ContainingProject.Name + uiItemFullName;
                    project = project.ParentProjectItem.ContainingProject;
                }
            }
            var hierarchy = (UIHierarchy)dte.Windows.Item(Constants.vsWindowKindSolutionExplorer).Object;
            uiItemFullName = hierarchy.UIHierarchyItems.Item(1).Name + uiItemFullName;
            hierarchy.GetItem(uiItemFullName).Select(vsUISelectionType.vsUISelectionTypeSelect);
        }
public static void SelectProject ( this DTE dte , Project project ) { Debug . Assert ( dte != null , " " ) ; dte . Windows . Item ( Constants . vsWindowKindSolutionExplorer ) . Activate ( ) ; var uiItemFullName = string . Empty ; if ( project != null ) { if ( project . Kind == VenusProjectGuid ) { var tokens = project . Name . Split ( new [ ] { ' \\ ' } ) ; uiItemFullName = tokens [ tokens . Length - 2 ] ; } else { uiItemFullName = project . Name ; } uiItemFullName = " \\ " + uiItemFullName ; while ( project . ParentProjectItem != null ) { uiItemFullName = " \\ " + project . ParentProjectItem . ContainingProject . Name + uiItemFullName ; project = project . ParentProjectItem . ContainingProject ; } } var hierarchy = ( UIHierarchy ) dte . Windows . Item ( Constants . vsWindowKindSolutionExplorer ) . Object ; uiItemFullName = hierarchy . UIHierarchyItems . Item ( 1 ) . Name + uiItemFullName ; hierarchy . GetItem ( uiItemFullName ) . Select ( vsUISelectionType . vsUISelectionTypeSelect ) ; }
Select the given project in the solution explorer.
Select the given project in the solution explorer .
// Venus projects have special names that needs additional process // Remove the useless part // Add the whole path to the item full name // Add the solution node to the item full name // Get the hierarchy item given the item full name and select the item
DTE
this
project
Project
the project to select
the project to select
dte
None