Visual Studio 宏列出项目而不是解决方案文件夹

发布于 2024-10-27 03:22:34 字数 299 浏览 7 评论 0原文

使用以下代码为我提供了解决方案文件夹而不是真实的项目。

projectName = DTE.Solution.SolutionBuild.StartupProjects(0)
For Each project In DTE.Solution.Projects
    If project.UniqueName = projectName Then
        Return project
    End If
Next

有没有办法可以循环遍历实际的项目节点?

我正在尝试从启动项目中读取属性。

Using the following code gives me Solution folders instead of real projects.

projectName = DTE.Solution.SolutionBuild.StartupProjects(0)
For Each project In DTE.Solution.Projects
    If project.UniqueName = projectName Then
        Return project
    End If
Next

Is there way I can loop through actual Project nodes?

I'm trying to read properties from the startup project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

青衫负雪 2024-11-03 03:22:34

我从未编写过任何 Visual Studio 宏,但这可能正是您正在寻找的。

projectName = DTE.Solution.SolutionBuild.StartupProjects(0)
For Each project In DTE.Solution.Projects
    If (project.ConfigurationManager IsNot Nothing) Then
        ' It's a project!
        If (project.UniqueName = projectName) Then Return project
    Else
        If (project.ProjectItems IsNot Nothing) Then
            For Each projectItem In project.ProjectItems
                If (projectItem.SubProject IsNot Nothing) Then
                   ' TODO: Recurse on projectItem.SubProject 
                End If
            Next
        End If
    End If
Next

我在那里留下了一个“TODO”,因为如果您想要处理嵌套(子)项目,您需要将其实际拉到一个可以递归调用的函数中。

我从 此链接< /a>,虽然它是 Visual Studio 2005 时代的材料,但它可能会让您朝着正确的方向前进。

I've never written any Visual Studio macros, but this may be what you are looking for.

projectName = DTE.Solution.SolutionBuild.StartupProjects(0)
For Each project In DTE.Solution.Projects
    If (project.ConfigurationManager IsNot Nothing) Then
        ' It's a project!
        If (project.UniqueName = projectName) Then Return project
    Else
        If (project.ProjectItems IsNot Nothing) Then
            For Each projectItem In project.ProjectItems
                If (projectItem.SubProject IsNot Nothing) Then
                   ' TODO: Recurse on projectItem.SubProject 
                End If
            Next
        End If
    End If
Next

I left a 'TODO in there, because you would need to actually pull this out into a function that you could recursively call if you are looking to deal with nested (sub) projects.

I got this solution from this link, and while it's Visual Studio 2005-era material, it might get you going in the right direction.

如何视而不见 2024-11-03 03:22:34

我认为您可能想检查 VS 常量,请尝试以下操作:

Private Function GetAllProjects() As Generic.List(Of Project)
    Dim lst As New Generic.List(Of Project)
    For Each proj As Project In DTE.Solution.Projects
    If proj.Kind = Constants.vsProjectKindSolutionItems Then
        lst.AddRange(GetSubProjects(proj.ProjectItems))
    Else
        lst.Add(proj)
    End If
    Next
    Return lst
End Function

Private Function GetSubProjects(ByVal pis As ProjectItems) As Generic.List(Of Project)
    Dim lst As New Generic.List(Of Project)
    For Each pi As ProjectItem In pis
    If pi.Kind = Constants.vsProjectItemKindSolutionItems Then
        lst.Add(pi.SubProject)
    ElseIf pi.Kind = Constants.vsProjectKindSolutionItems Then
        lst.AddRange(GetSubProjects(pi.ProjectItems))
    End If
    Next
    Return lst
End Function

它是我的博客中的较大宏的一部分,网址为 http://www.brianschmitt.com/2009/10/fixing-visual-studio-add-reference.html

I think you may want to check against the VS constants, try the following:

Private Function GetAllProjects() As Generic.List(Of Project)
    Dim lst As New Generic.List(Of Project)
    For Each proj As Project In DTE.Solution.Projects
    If proj.Kind = Constants.vsProjectKindSolutionItems Then
        lst.AddRange(GetSubProjects(proj.ProjectItems))
    Else
        lst.Add(proj)
    End If
    Next
    Return lst
End Function

Private Function GetSubProjects(ByVal pis As ProjectItems) As Generic.List(Of Project)
    Dim lst As New Generic.List(Of Project)
    For Each pi As ProjectItem In pis
    If pi.Kind = Constants.vsProjectItemKindSolutionItems Then
        lst.Add(pi.SubProject)
    ElseIf pi.Kind = Constants.vsProjectKindSolutionItems Then
        lst.AddRange(GetSubProjects(pi.ProjectItems))
    End If
    Next
    Return lst
End Function

Its part of a larger macro from my blog at http://www.brianschmitt.com/2009/10/fixing-visual-studio-add-reference.html

耀眼的星火 2024-11-03 03:22:34

要从解决方案文件夹获取项目,请使用属性 ProjectItem.SubProject

To Get the Project from Solution folder, use the property ProjectItem.SubProject

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文