次の方法で共有


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="https://schemas.microsoft.com/developer/msbuild/2003">

 

 

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

 

Imports <xmlns="https://schemas.microsoft.com/developer/msbuild/2003">

Public Class Form1

    Dim sample = _

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

            <SpecificVersion>False</SpecificVersion>

            <HintPath>..\..\..\..\binaries\x86chk\bin\i386\Microsoft.VisualStudio.CoreUtilityImplementation.dll</HintPath>

        </Reference>

    Function trimcomma(ByVal s As String)

        'strip anything past comma <Reference Include="somedllname, Version=9.0.0.0, 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

            System.Diagnostics.Debug.WriteLine(ref)

        Next

        Dim lbx As New ListBox

        lbx.Width = Me.Width

        lbx.Height = Me.Height

        lbx.DataSource = query.ToArray

        Me.Controls.Add(lbx)

        lbx.Visible = True

    End Sub

End Class

Comments

  • Anonymous
    January 29, 2008
    ....Interesting Carmelo Lisciotto

  • Anonymous
    February 10, 2008
    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 Mark