输出属于Visual Studio项目的文件列表

时间:2011-08-05 10:46:35

标签: visual-studio

我正在寻找一种方法来输出Visual Studio项目中所有文件的列表以供记录。

我原本以为这是可能的,但我找不到任何信息。我不是在谈论使用Sandcastle来连接XML注释,我只想要一个“简单”缩进的项目文件列表。

我猜我们可以针对Proj文件运行xsl文件,但希望有人已经有了解决方案吗?理想情况下,这将适用于2008年和2010年。

1 个答案:

答案 0 :(得分:1)

VS2008示例宏已经包含一个实际执行此操作的宏(将源/头文件列表打印到输出窗口)。在ListProj1个样本下,它被称为Utilities。如果没有它,这是代码:

Sub ListProj()
  Dim project As Project
  Dim projectObjects As Object()
  Dim window As Window
  Dim target As Object
  window = DTE.Windows.Item(Constants.vsWindowKindCommandWindow)
  projectObjects = DTE.ActiveSolutionProjects
  If projectObjects.Length = 0 Then
    Exit Sub
  End If
  project = DTE.ActiveSolutionProjects(0)
  If (DTE.ActiveWindow Is window) Then
    target = window.Object
  Else
    target = GetOutputWindowPane("List Project")
    target.Clear()
  End If
  ListProjAux(project.ProjectItems(), 0, target)
End Sub

Sub ListProjAux(ByVal projectItems As EnvDTE.ProjectItems, ByVal level As Integer, ByVal outputWinPane As Object)
    Dim projectItem As EnvDTE.ProjectItem
    For Each projectItem In projectItems
        If projectItem.Collection Is projectItems Then
            Dim projectItems2 As EnvDTE.ProjectItems
            Dim notSubCollection As Boolean
            OutputItem(projectItem, level, outputWinPane)
            '' Recurse if this item has subitems ...
            projectItems2 = projectItem.ProjectItems
            notSubCollection = projectItems2 Is Nothing
            If Not notSubCollection Then
                ListProjAux(projectItems2, level + 1, outputWinPane)
            End If
        End If
    Next
End Sub

Sub OutputItem(ByVal projectItem As EnvDTE.ProjectItem, ByVal level As Integer, ByVal outputWinPane As Object)
    Dim i As Integer = 0
    While (i < level)
        outputWinPane.OutputString("    ")
        i = i + 1
    End While
    outputWinPane.OutputString(projectItem.FileNames(1))
    outputWinPane.OutputString(Microsoft.VisualBasic.Constants.vbCrLf)
End Sub