Imports System Imports EnvDTE Imports EnvDTE80 Imports EnvDTE90 Imports System.Diagnostics Imports VSLangProj Imports System.Text Imports System.Windows Imports System.Windows.Forms Imports System.Collections.Generic Imports System.IO Imports System.Xml Public Module References Public Sub ResolveProjectReferences() Dim projects As Dictionary(Of String, Project) = New Dictionary(Of String, Project)() Dim unresolved As Stack(Of Project) = New Stack(Of Project) Dim log As StringWriter = New StringWriter() ' get all projects in the current solution and mark them as unresolved For Each project As Project In DTE.Solution.Projects If (project.Kind = PrjKind.prjKindVBProject) Or (project.Kind = PrjKind.prjKindCSharpProject) Then projects.Add(project.FullName, project) unresolved.Push(project) End If Next While unresolved.Count > 0 Dim project As Project = unresolved.Pop() log.WriteLine("Resolving {0}", project.Name) ' load the prject file (XML) Dim path As String = System.IO.Path.GetDirectoryName(project.FullName) Dim doc As XmlDocument = New XmlDocument() doc.Load(project.FullName) Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(doc.NameTable) nsmgr.AddNamespace("b", "http://schemas.microsoft.com/developer/msbuild/2003") ' find all project reference items For Each node As XmlNode In doc.SelectNodes("//b:ProjectReference", nsmgr) ' get the full path of the project reference Dim projFile As String = System.IO.Path.GetFullPath(System.IO.Path.Combine(path, node.Attributes("Include").Value)) If Not projects.ContainsKey(projFile) Then ' if the project is not already loaded, add it to the solution and mark it as unresolved log.WriteLine("Adding project {0}", projFile) Dim p As Project = DTE.Solution.AddFromFile(projFile) projects.Add(projFile, p) unresolved.Push(p) End If Next End While ' print actions to output window Dim outputPane As OutputWindowPane = GetOutputWindowPane("Macros") outputPane.OutputString(log.ToString()) End Sub Private Function GetOutputWindowPane(ByVal Name As String, Optional ByVal show As Boolean = True) As OutputWindowPane Dim window As Window Dim outputWindow As OutputWindow Dim outputWindowPane As OutputWindowPane window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput) If show Then window.Visible = True outputWindow = window.Object Try outputWindowPane = outputWindow.OutputWindowPanes.Item(Name) Catch e As System.Exception outputWindowPane = outputWindow.OutputWindowPanes.Add(Name) End Try outputWindowPane.Activate() Return outputWindowPane End Function End Module '' This class is used to set the proper parent to any UI that you may display from within a macro. '' See the AddClassicComRef macro for an example of how this is used Public Class WinWrapper Implements System.Windows.Forms.IWin32Window Overridable ReadOnly Property Handle() As System.IntPtr Implements System.Windows.Forms.IWin32Window.Handle Get Dim iptr As New System.IntPtr(DTE.MainWindow.HWnd) Return iptr End Get End Property End Class