场景: 在 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

相关文章:

  • 2022-03-06
  • 2022-12-23
  • 2021-07-10
  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-29
  • 2021-04-16
  • 2021-12-01
  • 2021-06-15
  • 2021-06-12
  • 2022-12-23
相关资源
相似解决方案