* SolutionParser.cs (ParseSolution): Use ProjectReference's
authorAnkit Jain <radical@corewars.org>
Tue, 15 Jun 2010 22:55:16 +0000 (22:55 -0000)
committerAnkit Jain <radical@corewars.org>
Tue, 15 Jun 2010 22:55:16 +0000 (22:55 -0000)
filename to locate if no guid is specified or project can't
be found by the guid.

svn path=/trunk/mcs/; revision=158985

mcs/tools/xbuild/ChangeLog
mcs/tools/xbuild/SolutionParser.cs

index 5b8f8255d3ba7274785a0937c34c0816b96e5853..acb79d418c39326d413770700097821c9e5062ca 100644 (file)
@@ -1,3 +1,9 @@
+2010-06-16  Ankit Jain  <jankit@novell.com>
+
+       * SolutionParser.cs (ParseSolution): Use ProjectReference's
+       filename to locate if no guid is specified or project can't
+       be found by the guid.
+
 2010-06-15  Ankit Jain  <jankit@novell.com>
 
        * xbuild/*/Microsoft.Common.targets (AssemblySearchPaths): Add
index 70748c8698fcf75b1858ec07e55c9607d078f20c..552b2f306306d9956730d9dc2539f0607e4d3102 100644 (file)
@@ -32,6 +32,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.IO;
@@ -135,7 +136,9 @@ namespace Mono.XBuild.CommandLine {
 
                        Match m = projectRegex.Match (line);
                        while (m.Success) {
-                               ProjectInfo projectInfo = new ProjectInfo (m.Groups[2].Value, m.Groups[3].Value);
+                               ProjectInfo projectInfo = new ProjectInfo (m.Groups[2].Value,
+                                                               Path.GetFullPath (Path.Combine (solutionDir,
+                                                                       m.Groups [3].Value.Replace ('\\', Path.DirectorySeparatorChar))));
                                if (String.Compare (m.Groups [1].Value, solutionFolderGuid,
                                                StringComparison.InvariantCultureIgnoreCase) == 0) {
                                        // Ignore solution folders
@@ -189,8 +192,8 @@ namespace Mono.XBuild.CommandLine {
                        }
 
                        foreach (ProjectInfo projectInfo in projectInfos.Values) {
-                               string filename = Path.Combine (solutionDir,
-                                                       projectInfo.FileName.Replace ('\\', Path.DirectorySeparatorChar));
+                               string filename = projectInfo.FileName;
+                               string projectDir = Path.GetDirectoryName (filename);
 
                                if (!File.Exists (filename)) {
                                        RaiseWarning (0, String.Format ("Project file {0} referenced in the solution file, " +
@@ -207,12 +210,34 @@ namespace Mono.XBuild.CommandLine {
                                }
 
                                foreach (BuildItem bi in currentProject.GetEvaluatedItemsByName ("ProjectReference")) {
+                                       ProjectInfo info = null;
                                        string projectReferenceGuid = bi.GetEvaluatedMetadata ("Project");
-                                       Guid guid = new Guid (projectReferenceGuid);
-                                       ProjectInfo info;
-                                       if (projectInfos.TryGetValue (guid, out info))
-                                               // ignore if not found
-                                               projectInfo.Dependencies [guid] = info;
+                                       bool hasGuid = !String.IsNullOrEmpty (projectReferenceGuid);
+
+                                       // try to resolve the ProjectReference by GUID
+                                       // and fallback to project filename
+
+                                       if (hasGuid) {
+                                               Guid guid = new Guid (projectReferenceGuid);
+                                               projectInfos.TryGetValue (guid, out info);
+                                       }
+
+                                       if (info == null || !hasGuid) {
+                                               // Project not found by guid or guid not available
+                                               // Try to find by project file
+
+                                               string fullpath = Path.GetFullPath (Path.Combine (projectDir, bi.Include.Replace ('\\', Path.DirectorySeparatorChar)));
+                                               info = projectInfos.Values.FirstOrDefault (pi => pi.FileName == fullpath);
+
+                                               if (info == null)
+                                                       RaiseWarning (0, String.Format (
+                                                                       "{0}: ProjectReference '{1}' not found, neither by guid '{2}' nor by project file name '{3}'.",
+                                                                       filename, bi.Include, projectReferenceGuid, fullpath));
+
+                                       }
+
+                                       if (info != null)
+                                               projectInfo.Dependencies [info.Guid] = info;
                                }
                        }