问题描述
我正在寻找一种方法来输出 Visual Studio 项目中所有文件的列表以用于文档目的.
I'm looking for a way to output a list of all files in a Visual Studio project for documentation purposes.
我原以为这是可能的,但我找不到任何信息.我不是在谈论使用 Sandcastle 来连接 XML 注释,我只是想要一个简单"的项目文件缩进列表.
I would have thought this would be possible but I can't find any info. I'm not talking about using Sandcastle to hook up to XML comments, I just want a "simple" indented list of project files.
我猜我们可以针对 Proj 文件运行 xsl 文件,但希望有人已经找到了解决方案?理想情况下,这适用于 2008 年和 2010 年.
I'm guessing we could run an xsl file against the Proj file but hopefully somebody has already got a solution for this? Ideally this would work on both 2008 and 2010.
推荐答案
VS2008 示例宏已经包含一个实际执行此操作的宏(将源/头文件列表打印到输出窗口).它在 Utilities
示例下称为 ListProj1
.这是代码,以防您没有它:
The VS2008 sample macros already contain a macro that practically does this (prints a list of source/header file to the output window). It's called ListProj1
, under the Utilities
samples. Here's the code in case you don't have it:
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
这篇关于输出属于 Visual Studio 项目的文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!