In a Visual Studio extension I need to iterate through all the projects in the loaded solution and find all Dependencies (both NuGet packages as well as assemblies). The following code works fine for old non-SDK style projects but not for the new SDK-style projects.
var dte = ApplicationObject; // DTE object
if (dte == null || dte.Solution == null || !dte.Solution.IsOpen)
{
return;
}
foreach (Project project in dte.Solution.Projects)
{
var vsProj = project.Object as VSProject;
if (vsProj == null || vsProj.References == null)
{
// Project not loaded
continue;
}
foreach (Reference reference in vsProj.References)
{
if (reference.SourceProject != null
|| reference.Type != prjReferenceType.prjReferenceTypeAssembly)
{
// Skip over non assembly references
continue;
}
// reference.Name contains the reference name
}
}
In the new SDK-style projects "references" is now called Dependencies but there is no such property on VSProject
. So what is the way to get this for SDK-style projects?