简体   繁体   English

如何使用VS宏访问SolutionFolders中的项目?

[英]How do I access projects in SolutionFolders with VS macros?

I know that I could iterate over the projects of a solution with macros ( more or less ). 我知道我可以遍历具有( 或多或少 )宏的解决方案的项目。

But the top level of my SLN contains of five solution folders. 但是我的SLN的顶层包含五个解决方案文件夹。 I only obtain these five folders, but not their entries. 我仅获得这五个文件夹,而不获得它们的条目。

I guess that the Kind of a Project object could tell me whether it's a real project or just a folder. 我猜想一个Project对象的Kind可以告诉我它是一个真实的项目还是一个文件夹。 But I cannot find any reference how to find out that. 但是我找不到任何参考资料可以找到答案。


Edit: 编辑:
I know that there's only one solution. 我知道只有一种解决方案。 With "solution folders" I mean those folders created within a solution using Solution Explorer → Right Click Solution → Add → New Solution Folder . “解决方案文件夹”是指使用解决方案资源管理器在解决方案中创建的那些文件夹→右键单击解决方案→添加→新解决方案文件夹 This creates a new logical folder that gives you the opportunity to organize the projects of the solution in sub-folders. 这将创建一个新的逻辑文件夹,使您有机会在子文件夹中组织解决方案的项目。

This will give you an idea 这会给你一个想法

Sub ListSolutionFolders()
        Dim solutionFolder As Project
        Dim solutionFolders As Projects
        Dim name As String
        Dim type As String
        Dim projects As ProjectItems
        Dim project As ProjectItem

        solutionFolders = DTE.Solution.Projects
        For Each solutionFolder In solutionFolders
            name = solutionFolder.Name
            projects = solutionFolder.ProjectItems

            For Each project In projects
                If Not project.SubProject.Kind Is Nothing Then
                    'this is a real project
                    type = project.SubProject.Kind
                Else
                    'Not a project
                End If
            Next
        Next
    End Sub

Take note of the type, it is a GUID and you look at this link for what it means http://msdn.microsoft.com/en-us/library/hb23x61k%28v=vs.80%29.aspx Other project types like SSRS is not listed there but outputs a GUID as well 记下该类型,它是一个GUID,您可以在此链接中查看其含义: http://msdn.microsoft.com/zh-cn/library/hb23x61k%28v=vs.80%29.aspx其他项目类型像SSRS不在此处列出,但也会输出GUID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM