VS宏 之 选中解决方案中的文件

场景: 在 VS2010 中通过文件路径打开文件后,如何在解决方案中选中,定位? 没有找到命令.所以自己写了一个宏来实现 .

 引入 system.core 

  

    'Udi 2012年9月20日
    Sub SelectInSolution()
        Dim fileFullName = DTE.ActiveDocument.FullName
        Dim solutionFullName = DTE.Solution.FullName

        Dim solutionPath = solutionFullName.Substring(0, solutionFullName.LastIndexOf("\"))

        Dim filePath = fileFullName.Substring(solutionPath.Length)

        Dim soPath = "LongFor_PM\Host" + filePath


        DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
        DTE.ActiveWindow.Object.GetItem("LongFor_PM\Host").UIHierarchyItems.Expanded = True


        Dim sect = soPath.Substring("LongFor_PM\Host\".Length).Split("\")


        For i As Integer = 0 To sect.Length - 1
            If sect(i) = "MyBiz" Then sect(i) = "PmBiz"

            DTE.ActiveWindow.Object.GetItem("LongFor_PM\Host\" + String.Join("\", System.Linq.Enumerable.Take(sect, i + 1).ToArray())).UIHierarchyItems.Expanded = True
        Next

        soPath = soPath.Replace("\MyBiz\", "\PmBiz\")
        DTE.ActiveWindow.Object.GetItem(soPath).Select(vsUISelectionType.vsUISelectionTypeSelect)

    End Sub
posted @ 2012-09-06 13:39  NewSea  阅读(668)  评论(0编辑  收藏  举报