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


Comments (2)
  1. Carmelo Lisciotto says:


    Carmelo Lisciotto

  2. Mark Gordon says:

    Hey Calvin,

    Given what a great tool FoxPro was especially for middle tier business objects, is there a reason why the core VFP language is not being incorporated into Visual Studio? I’m migrating a VFP application to VS and I bet I have at least 5-10k lines of extra code in the VS application compared to the FoxPro application so far. Granted this is a n-tier application and I’m seperating much of the vs generated code that mixes data access into the UI.

    Despite Linq and Data Readers, Visual Studio is still not even in the same ballpark as VFP… Besides the lack of data support, VS is just so bloated there are 20 different way to perform each task, is that really necessary? This product is really in need of some refinement.

    It is just frustrating — Man I miss VB 6 and VFP.

    Thanks for your time


Comments are closed.

Skip to main content