views:

34

answers:

2

I have solution sln, that has many csproj projects.

anyone know a way to programmatically read the list of References of all csproj projects in a VS2008 of sln file?

+1  A: 

csproj files are just XML files. You can use XDocument from the .NET framework for this. I've done it for VS2010, but in VS2008 the tags are almost the same.

Example for VS2010, you have to verify the tags and namespace:

XElement projectNode = XElement.Load(fileName);
XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003";
var referenceNodes = projectNode.Descendants(ns + "ItemGroup").Descendants(ns + "Reference")

You might also wanna check for the ProjectReference tag. Hope that helps.

testalino
great, another reference: http://stackoverflow.com/questions/1191151/reading-the-list-of-references-from-csproj-files ; and how can I know the csproj files projects of a solution sln ? any API, SDK, scripting code ? any sample code ?
alhambraeidos
the solution file is not xml, so you can't parse it with the method described. you can easily parse the sln file for projects when using Regex, you don't need an API for this. This is a different question though (which you can ask here), please accept my answer to your original question if it helped you out.
testalino
+1  A: 

Not sure if it fits your needs, but once the solution is loaded into Visual Studio you can easily examine it using CodeModel API, using a simple addin or even macro:

Imports EnvDTE
Imports VSLangProj

Public Module Module1
    Public Sub ShowAllReferences()
        Dim sol As Solution = DTE.Solution
        For i As Integer = 1 To sol.Projects.Count
            Dim proj As Project = sol.Projects.Item(i)
            Dim vsProj As VSProject = DirectCast(proj.Object, VSProject)

            For Each reference As Reference In vsProj.References
                MsgBox(reference.Description)
            Next
        Next
    End Sub

End Module
Oleg Tkachenko
Can I share custom macros of VS2008 in Team Foundation Server ?? My company has many developers working with TFS.
alhambraeidos