Reading the list of References from All csproj project of solution sln (programmatically)

╄→гoц情女王★ 提交于 2019-12-23 10:55:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!