Visual Studio Macro : List Project Dependencies

 

Una macro di Visual Studio per elencare tutte le dipendenze di un progetto della solution
A Visual Studio macro that lists build dependencies of a project

    Sub CollectProjectDependencies(ByVal Project As VSLangProj.VSProject _
, ByVal Dependencies As Hashtable)
Dim BuildDependency As EnvDTE.BuildDependency = _
DTE.Solution.SolutionBuild.BuildDependencies.Item(Project.Project) Dim RequiredProjects As System.Array = BuildDependency.RequiredProjects For Each RequiredProjectObject As Object In RequiredProjects Dim RequiredProject As EnvDTE.Project = RequiredProjectObject If Not Dependencies.ContainsKey(RequiredProject.UniqueName) Then Dependencies.Add(RequiredProject.UniqueName, RequiredProject.Object) CollectProjectDependencies(RequiredProject.Object, Dependencies) End If Next End Sub

 

Un esempi di chiamata alla macro indicando lo UniqueName del progetto
Sample code to call the macro passing the project  UniqueName

        Dim Prj As EnvDTE.Project
        Try
            Prj = DTE.Solution.Projects.Item("NummableTypes\src\Types\Types.csproj")
        Catch
            MsgBox("Project not in the solution.", MsgBoxStyle.Exclamation)
            Return
        End Try

        Dim VSProject As VSLangProj.VSProject = Prj.Object
        Dim Dependencies As Hashtable = New Hashtable()
        CollectProjectDependencies(VSProject, Dependencies)

        DTE.ExecuteCommand("Debug.Output")
        DTE.ExecuteCommand("View.Output")
        For Each Dict As DictionaryEntry In Dependencies
            DTE.ToolWindows.OutputWindow.ActivePane.OutputString(Dict.Key _
+ Environment.NewLine) Next

 

Niente paura, ecco il codice per conoscere gli UniqueName dei progetti caricati:
And here is the code to get all the UniqueNames of the projects

    Sub ShowAllProjectsUniqueNames()
        If Not DTE.Solution.IsOpen Then
            MsgBox("Open a solution.", MsgBoxStyle.Exclamation)
            Return
        End If
For Each Project As EnvDTE.Project In DTE.Solution.Projects MsgBox(Project.UniqueName()) Next End Sub

Print | posted @ venerdì 14 marzo 2008 16:18

Comments have been closed on this topic.