问题
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:
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.
回答2:
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
来源:https://stackoverflow.com/questions/3787116/reading-the-list-of-references-from-all-csproj-project-of-solution-sln-programm