}
ProcessXml (parent);
+
+ ProjectCollection.AddProject (this);
}
static readonly char [] item_sep = {';'};
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
+using System.Xml;
namespace Microsoft.Build.Evaluation
{
readonly int max_node_count;
+ public void AddProject (Project project)
+ {
+ this.loaded_projects.Add (project);
+ if (ProjectAdded != null)
+ ProjectAdded (this, new ProjectAddedToProjectCollectionEventArgs (project.Xml));
+ }
+
[MonoTODO]
public int Count {
get { return loaded_projects.Count; }
public ICollection<Project> GetLoadedProjects (string fullPath)
{
- return LoadedProjects.Where (p => Path.GetFullPath (p.FullPath) == Path.GetFullPath (fullPath)).ToList ();
+ return LoadedProjects.Where (p => p.FullPath != null && Path.GetFullPath (p.FullPath) == Path.GetFullPath (fullPath)).ToList ();
}
readonly IDictionary<string, string> global_properties;
}
readonly List<Project> loaded_projects = new List<Project> ();
-
+
+ public Project LoadProject (string fileName)
+ {
+ return LoadProject (fileName, DefaultToolsVersion);
+ }
+
+ public Project LoadProject (string fileName, string toolsVersion)
+ {
+ return LoadProject (fileName, toolsVersion);
+ }
+
+ public Project LoadProject (string fileName, IDictionary<string,string> globalProperties, string toolsVersion)
+ {
+ return new Project (fileName, globalProperties, toolsVersion);
+ }
+
+ // These methods somehow don't add the project to ProjectCollection...
+ public Project LoadProject (XmlReader xmlReader)
+ {
+ return LoadProject (xmlReader, DefaultToolsVersion);
+ }
+
+ public Project LoadProject (XmlReader xmlReader, string toolsVersion)
+ {
+ return LoadProject (xmlReader, null, toolsVersion);
+ }
+
+ public Project LoadProject (XmlReader xmlReader, IDictionary<string,string> globalProperties, string toolsVersion)
+ {
+ return new Project (xmlReader, globalProperties, toolsVersion);
+ }
+
[MonoTODO]
public ICollection<Project> LoadedProjects {
get { return loaded_projects; }
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
+//
+// It is not always consistent to reuse Project and its evaluation stuff mostly because
+// both BuildParameters.ctor() and Project.ctor() takes arbitrary ProjectCollection, which are not very likely eqivalent
+// (as BuildParameters.ctor(), unlike Project.ctor(...), is known to create a new ProjectCollection instance).
+//
+// However, that inconsistency could happen even if you only use ProjectInstance and BuildParameters.
+// They both have constructors that take ProjectCollection and there is no guarantee that the arguments are the same.
+// BuildManager.Build() does not fail because of inconsistent ProjectCollection instance on .NET. So we can ignore that.
+//
+
namespace Microsoft.Build.Execution
{
public class ProjectInstance
inst.Build ();
Assert.AreEqual (0, coll.Count, "#2");
}
+
+ [Test]
+ public void GetLoadedProjectsWithoutFullPath ()
+ {
+ string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
+ var xml = XmlReader.Create (new StringReader (project_xml));
+ var root = ProjectRootElement.Create (xml);
+ string path = Path.GetFullPath ("foo.xml");
+ var pc = new ProjectCollection ();
+
+ pc.LoadProject (XmlReader.Create (new StringReader (project_xml), null, path));
+ Assert.AreEqual (0, pc.GetLoadedProjects (path).Count, "#1"); // huh?
+
+ new Project (root, null, null, pc);
+ Assert.AreEqual (0, pc.GetLoadedProjects (path).Count, "#2"); // huh?
+ }
+
+ [Test]
+ public void GetLoadedProjectsSuccess ()
+ {
+ string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
+ var xml = XmlReader.Create (new StringReader (project_xml));
+ var root = ProjectRootElement.Create (xml);
+ string path = Path.GetFullPath ("foo.xml");
+ var pc = new ProjectCollection ();
+
+ var proj = new Project (root, null, null, pc);
+ // this order also matters for test; It sets FullPath after Project.ctor(), and should still work.
+ root.FullPath = "foo.xml";
+
+ Assert.AreEqual (1, pc.GetLoadedProjects (path).Count, "#1"); // wow ok...
+ Assert.AreEqual (proj, pc.GetLoadedProjects (path).First (), "#2");
+ }
}
}