1
Vote

Project reference doesn't work correctly if referenced project is in a solution folder

description

  1. Create a Solution folder
  2. Create a C# project inside the just created folder.
  3. Create a whatever project using MPF (Visual T# in the attached Image)
  4. Make a reference from MPF project to C# project: an exclamation sign appears. Reference is not resolved and Intellisense does not work!
     
    See attached image.

file attachments

comments

ldubois wrote Apr 18, 2011 at 1:55 PM

Here is my patche (in ProjectReferenceNode.cs):
    /// <summary>
    /// Gets the automation object for the referenced project.
    /// </summary>
    internal EnvDTE.Project ReferencedProjectObject
    {
        get
        {
            // If the referenced project is null then re-read.
            if (this.referencedProject == null)
            {
              // Search for the project in the collection of the projects in the
              // current solution.
              EnvDTE.DTE dte = (EnvDTE.DTE)this.ProjectMgr.GetService( typeof( EnvDTE.DTE ) );
              if( ( null == dte ) || ( null == dte.Solution ) )
              {
                return null;
              }

              foreach( EnvDTE.Project prj in dte.Solution.Projects )
                if( IsOrContainReferencedProject( prj ) )
                  break;
            }

            return this.referencedProject;
        }
        set
        {
            this.referencedProject = value;
        }
    }


    private bool IsOrContainReferencedProject( EnvDTE.Project prj )
    {
      //Skip this project if it is an umodeled project (unloaded)
      if( string.Compare( EnvDTE.Constants.vsProjectKindUnmodeled, prj.Kind, StringComparison.OrdinalIgnoreCase ) == 0 )
      {
        return false;
      }
      if( string.Compare( EnvDTE.Constants.vsProjectKindSolutionItems, prj.Kind, StringComparison.OrdinalIgnoreCase ) == 0 )
      {
        foreach( EnvDTE.ProjectItem projectItem in prj.ProjectItems )
        {
          EnvDTE.Project project = projectItem.Object as EnvDTE.Project;
          if( project != null &&
              IsOrContainReferencedProject( project ) )
            return true;
        }
        return false;
      }

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

        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.
          return false;
        }
      }
      catch( ArgumentException )
      {
        return false;
      }
      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.
          return false;
        }
      }
      catch( ArgumentException )
      {
        return false;
      }
      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;
        return true;
      }
      return false;
    }

kiquenet wrote Aug 28, 2012 at 12:13 PM

@idubois, What is NativeMethods.IsSamePath ?

ldubois wrote Aug 29, 2012 at 12:31 AM

@kiquenet, this is a method provided by MPF that compare two paths and returns true iif they are equal.

wrote Feb 14, 2013 at 2:58 AM