Skip to content

Commit

Permalink
Merge pull request CosmosOS#57 from kant2002/Issue-10
Browse files Browse the repository at this point in the history
Fix resolution of references inside solution folder.
  • Loading branch information
mterwoord committed Jan 23, 2015
2 parents 087ab24 + b7b965e commit fcdda66
Showing 1 changed file with 93 additions and 55 deletions.
148 changes: 93 additions & 55 deletions source/MPF/10.0/Src/CSharp/ProjectReferenceNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,61 +137,8 @@ internal EnvDTE.Project ReferencedProjectObject
{
return null;
}
foreach (EnvDTE.Project prj in dte.Solution.Projects)
{
//Skip this project if it is an umodeled project (unloaded)
if (string.Compare(EnvDTE.Constants.vsProjectKindUnmodeled, prj.Kind, StringComparison.OrdinalIgnoreCase) == 0)
{
continue;
}

// Get the full path of the current project.
EnvDTE.Property pathProperty = null;
try
{
if (prj.Properties == null)
{
continue;
}

pathProperty = prj.Properties.Item("FullPath");
if (null == pathProperty)
{
// The full path should alway be availabe, but if this is not the
// case then we have to skip it.
continue;
}
}
catch (ArgumentException)
{
continue;
}
string prjPath = pathProperty.Value.ToString();
EnvDTE.Property fileNameProperty = null;
// Get the name of the project file.
try
{
fileNameProperty = prj.Properties.Item("FileName");
if (null == fileNameProperty)
{
// Again, this should never be the case, but we handle it anyway.
continue;
}
}
catch (ArgumentException)
{
continue;
}
prjPath = System.IO.Path.Combine(prjPath, fileNameProperty.Value.ToString());

// If the full path of this project is the same as the one of this
// reference, then we have found the right project.
if (NativeMethods.IsSamePath(prjPath, referencedProjectFullPath))
{
this.referencedProject = prj;
break;
}
}

this.referencedProject = this.FindReferencedProject(dte.Solution.Projects);
}

return this.referencedProject;
Expand Down Expand Up @@ -517,6 +464,97 @@ private bool IsReferenceInCycle(Guid projectGuid)

return circular != 0;
}

private EnvDTE.Project FindReferencedProject(System.Collections.IEnumerable projects)
{
EnvDTE.Project refProject = null;

// Search for the project in the collection of the projects in the current solution.
foreach (EnvDTE.Project prj in projects)
{
//Skip this project if it is an umodeled project (unloaded)
if (string.Compare(EnvDTE.Constants.vsProjectKindUnmodeled, prj.Kind, StringComparison.OrdinalIgnoreCase) == 0)
{
continue;
}

// Recursively iterate solution folder for the project.
if (string.Compare(EnvDTE.Constants.vsProjectKindSolutionItems, prj.Kind, StringComparison.OrdinalIgnoreCase) == 0)
{
var containedProjects = GetContainerProjects(prj);

refProject = FindReferencedProject(containedProjects);
if (refProject != null)
return refProject;
}

// Get the full path of the current project.
EnvDTE.Property pathProperty = null;
try
{
if (prj.Properties == null)
{
continue;
}

pathProperty = prj.Properties.Item("FullPath");
if (null == pathProperty)
{
// The full path should alway be availabe, but if this is not the
// case then we have to skip it.
continue;
}
}
catch (ArgumentException)
{
continue;
}
string prjPath = pathProperty.Value.ToString();
EnvDTE.Property fileNameProperty = null;
// Get the name of the project file.
try
{
fileNameProperty = prj.Properties.Item("FileName");
if (null == fileNameProperty)
{
// Again, this should never be the case, but we handle it anyway.
continue;
}
}
catch (ArgumentException)
{
continue;
}
prjPath = System.IO.Path.Combine(prjPath, fileNameProperty.Value.ToString());

// If the full path of this project is the same as the one of this
// reference, then we have found the right project.
if (NativeMethods.IsSamePath(prjPath, referencedProjectFullPath))
{
refProject = prj;
break;
}
}
return refProject;
}

private static System.Collections.IEnumerable GetContainerProjects(EnvDTE.Project prj)
{
foreach (var obj in prj.ProjectItems)
{
var pi = obj as EnvDTE.ProjectItem;
if (pi == null)
{
continue;
}

var nestedPrj = pi.Object as EnvDTE.Project;
if (nestedPrj != null)
{
yield return nestedPrj;
}
}
}
#endregion
}

Expand Down

0 comments on commit fcdda66

Please sign in to comment.