Use XLINQ to query the references in your project

Visual studio creates project files for you for the various languages, such as C++, C#, VB. These files are XML format, and can thus be queried.


Try this: open any non-temporary Visual Studio project (see Use temporary projects in Visual Studio), right click on it in solution explorer, choose unload, then right click again, then choose edit. This opens the Proj file (.vbproj,.csproj) in the XML editor


I wanted a way to get just the References in a list, so I started to write an XLINQ query of the XML.


I kept getting no results, until I saw that the XML has a namespace that I didn’t notice at first:

<?xml version="1.0" encoding="utf-8"?>

<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="">



So I just needed to add an IMPORTS for the XML NameSpace


Imports <xmlns="">

Public Class Form1

    Dim sample = _

        <Reference Include="Microsoft.VisualStudio.CoreUtilityImplementation, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">




    Function trimcomma(ByVal s As String)

        'strip anything past comma <Reference Include="somedllname, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">

        If s.IndexOf(",") > 0 Then

            Return s.Substring(0, s.IndexOf(","))

        End If

        Return s

    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' the path of the current project

        Dim xmlfile = My.Application.Info.DirectoryPath.Replace("\bin\Debug", "") + "\" + My.Application.Info.AssemblyName + ".vbproj"

        Dim xmlSrc = XDocument.Load(xmlfile)

        Me.Height = 800

        Me.Width = 1000

        Dim query = From a In xmlSrc...<Reference> _

                 Select r1 = trimcomma(a.@<Include>)

        For Each ref In query



        Dim lbx As New ListBox

        lbx.Width = Me.Width

        lbx.Height = Me.Height

        lbx.DataSource = query.ToArray


        lbx.Visible = True

    End Sub

End Class