读取解决方案SLN的所有CSPROJ项目的参考列表(以编程方式)
-
05-10-2019 - |
题
我有解决方案SLN,其中有许多CSPROJ项目。
任何人都知道一种方法来编程阅读SLN文件VS2008中所有CSPROJ项目的参考列表吗?
解决方案
CSPROJ文件只是XML文件。您可以为此使用.NET框架中的Xdocument。我已经为VS2010完成了此操作,但是在VS2008中,标签几乎相同。
VS2010的示例,您必须验证标签和名称空间:
XElement projectNode = XElement.Load(fileName);
XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003";
var referenceNodes = projectNode.Descendants(ns + "ItemGroup").Descendants(ns + "Reference")
您可能还想检查项目ReReference标签。希望有帮助。
其他提示
不确定是否适合您的需求,但是将解决方案加载到Visual Studio中,您可以使用CodeModel API轻松地检查它,并使用简单的addin甚至宏:
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
不隶属于 StackOverflow