Merge pull request #1041 from mono/staged-cyclic-builds
[mono.git] / mcs / class / Microsoft.Build / Microsoft.Build.Evaluation / Project.cs
1 //
2 // Project.cs
3 //
4 // Author:
5 //   Leszek Ciesielski (skolima@gmail.com)
6 //   Rolf Bjarne Kvinge (rolf@xamarin.com)
7 //   Atsushi Enomoto (atsushi@xamarin.com)
8 //
9 // (C) 2011 Leszek Ciesielski
10 // Copyright (C) 2011,2013 Xamarin Inc. (http://www.xamarin.com)
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using System;
33 using System.Collections.Generic;
34 using System.Diagnostics;
35 using System.IO;
36 using System.Linq;
37 using System.Text;
38 using System.Xml;
39 using Microsoft.Build.Construction;
40 using Microsoft.Build.Exceptions;
41 using Microsoft.Build.Execution;
42 using Microsoft.Build.Framework;
43 using Microsoft.Build.Internal;
44 using Microsoft.Build.Internal.Expressions;
45 using Microsoft.Build.Logging;
46 using System.Collections;
47
48 // Basically there are two semantic Project object models and their relationship is not obvious
49 // (apart from Microsoft.Build.Construction.ProjectRootElement which is a "construction rule").
50 //
51 // Microsoft.Build.Evaluation.Project holds some "editable" project model, and it supports
52 // detailed loader API (such as Items and AllEvaluatedItems).
53 // ProjectPoperty holds UnevaluatedValue and gives EvaluatedValue too.
54 //
55 // Microsoft.Build.Execution.ProjectInstance holds "snapshot" of a project, and it lacks
56 // detailed loader API. It does not give us Unevaluated property value.
57 // On the other hand, it supports Targets object model. What Microsoft.Build.Evaluation.Project
58 // offers there is actually a list of Microsoft.Build.Execution.ProjectInstance objects.
59 // It should be also noted that only ProjectInstance has Evaluate() method (Project doesn't).
60 //
61 // And both API holds different set of descendant types for each and cannot really share the
62 // loader code. That is lame.
63 //
64 // So, can either of them be used to construct the other model? Both API models share the same
65 // "governor", which is Microsoft.Build.Evaluation.ProjectCollection/ Project is added to
66 // its LoadedProjects list, while ProjectInstance isn't. Project cannot be loaded to load
67 // a ProjectInstance, at least within the same ProjectCollection.
68 //
69 // On the other hand, can ProjectInstance be used to load a Project? Maybe. Since Project and
70 // its descendants need Microsoft.Build.Construction.ProjectElement family as its API model
71 // is part of the public API. Then I still have to understand how those AllEvaluatedItems/
72 // AllEvaluatedProperties members make sense. EvaluationCounter is another propery in question.
73
74 namespace Microsoft.Build.Evaluation
75 {
76         [DebuggerDisplay ("{FullPath} EffectiveToolsVersion={ToolsVersion} #GlobalProperties="
77         + "{data.globalProperties.Count} #Properties={data.Properties.Count} #ItemTypes="
78         + "{data.ItemTypes.Count} #ItemDefinitions={data.ItemDefinitions.Count} #Items="
79         + "{data.Items.Count} #Targets={data.Targets.Count}")]
80         public class Project
81         {
82                 public Project (XmlReader xml)
83                         : this (ProjectRootElement.Create (xml))
84                 {
85                 }
86
87                 public Project (XmlReader xml, IDictionary<string, string> globalProperties,
88                                               string toolsVersion)
89                         : this (ProjectRootElement.Create (xml), globalProperties, toolsVersion)
90                 {
91                 }
92
93                 public Project (XmlReader xml, IDictionary<string, string> globalProperties,
94                                               string toolsVersion, ProjectCollection projectCollection)
95                         : this (ProjectRootElement.Create (xml), globalProperties, toolsVersion, projectCollection)
96                 {
97                 }
98
99                 public Project (XmlReader xml, IDictionary<string, string> globalProperties,
100                                               string toolsVersion, ProjectCollection projectCollection,
101                                               ProjectLoadSettings loadSettings)
102                         : this (ProjectRootElement.Create (xml), globalProperties, toolsVersion, projectCollection, loadSettings)
103                 {
104                 }
105
106                 public Project (ProjectRootElement xml) : this (xml, null, null)
107                 {
108                 }
109
110                 public Project (ProjectRootElement xml, IDictionary<string, string> globalProperties,
111                                               string toolsVersion)
112                         : this (xml, globalProperties, toolsVersion, ProjectCollection.GlobalProjectCollection)
113                 {
114                 }
115
116                 public Project (ProjectRootElement xml, IDictionary<string, string> globalProperties,
117                                               string toolsVersion, ProjectCollection projectCollection)
118                         : this (xml, globalProperties, toolsVersion, projectCollection, ProjectLoadSettings.Default)
119                 {
120                 }
121
122                 public Project (ProjectRootElement xml, IDictionary<string, string> globalProperties,
123                                               string toolsVersion, ProjectCollection projectCollection,
124                                               ProjectLoadSettings loadSettings)
125                 {
126                         if (projectCollection == null)
127                                 throw new ArgumentNullException ("projectCollection");
128                         this.Xml = xml;
129                         this.GlobalProperties = globalProperties ?? new Dictionary<string, string> ();
130                         this.ToolsVersion = toolsVersion;
131                         this.ProjectCollection = projectCollection;
132                         this.load_settings = loadSettings;
133
134                         Initialize ();
135                 }
136
137                 public Project (string projectFile)
138                         : this (projectFile, null, null)
139                 {
140                 }
141
142                 public Project (string projectFile, IDictionary<string, string> globalProperties,
143                                 string toolsVersion)
144                 : this (projectFile, globalProperties, toolsVersion, ProjectCollection.GlobalProjectCollection, ProjectLoadSettings.Default)
145                 {
146                 }
147
148                 public Project (string projectFile, IDictionary<string, string> globalProperties,
149                                 string toolsVersion, ProjectCollection projectCollection)
150                 : this (projectFile, globalProperties, toolsVersion, projectCollection, ProjectLoadSettings.Default)
151                 {
152                 }
153
154                 public Project (string projectFile, IDictionary<string, string> globalProperties,
155                                 string toolsVersion, ProjectCollection projectCollection,
156                                 ProjectLoadSettings loadSettings)
157                         : this (ProjectRootElement.Create (projectFile), globalProperties, toolsVersion, projectCollection, loadSettings)
158                 {
159                 }
160
161                 ProjectLoadSettings load_settings;
162
163                 public IDictionary<string, string> GlobalProperties { get; private set; }
164
165                 public ProjectCollection ProjectCollection { get; private set; }
166
167                 public string ToolsVersion { get; private set; }
168
169                 public ProjectRootElement Xml { get; private set; }
170
171                 string dir_path;
172                 Dictionary<string, ProjectItemDefinition> item_definitions;
173                 List<ResolvedImport> raw_imports;
174                 List<ProjectItem> raw_items;
175                 List<ProjectItem> all_evaluated_items;
176                 List<ProjectProperty> properties;
177                 Dictionary<string, ProjectTargetInstance> targets;
178
179                 void Initialize ()
180                 {
181                         dir_path = Directory.GetCurrentDirectory ();
182                         raw_imports = new List<ResolvedImport> ();
183                         item_definitions = new Dictionary<string, ProjectItemDefinition> ();
184                         targets = new Dictionary<string, ProjectTargetInstance> ();
185                         raw_items = new List<ProjectItem> ();
186                         
187                         properties = new List<ProjectProperty> ();
188                 
189                         foreach (DictionaryEntry p in Environment.GetEnvironmentVariables ())
190                                 // FIXME: this is kind of workaround for unavoidable issue that PLATFORM=* is actually given
191                                 // on some platforms and that prevents setting default "PLATFORM=AnyCPU" property.
192                                 if (!string.Equals ("PLATFORM", (string) p.Key, StringComparison.OrdinalIgnoreCase))
193                                         this.properties.Add (new EnvironmentProjectProperty (this, (string)p.Key, (string)p.Value));
194                         foreach (var p in GlobalProperties)
195                                 this.properties.Add (new GlobalProjectProperty (this, p.Key, p.Value));
196                         var tools = ProjectCollection.GetToolset (this.ToolsVersion) ?? ProjectCollection.GetToolset (this.ProjectCollection.DefaultToolsVersion);
197                         foreach (var p in ProjectCollection.GetReservedProperties (tools, this))
198                                 this.properties.Add (p);
199                         foreach (var p in ProjectCollection.GetWellKnownProperties (this))
200                                 this.properties.Add (p);
201
202                         ProcessXml ();
203                         
204                         ProjectCollection.AddProject (this);
205                 }
206                 
207                 void ProcessXml ()
208                 {
209                         // this needs to be initialized here (regardless of that items won't be evaluated at property evaluation;
210                         // Conditions could incorrectly reference items and lack of this list causes NRE.
211                         all_evaluated_items = new List<ProjectItem> ();
212
213                         // property evaluation happens couple of times.
214                         // At first step, all non-imported properties are evaluated TOO, WHILE those properties are being evaluated.
215                         // This means, Include and IncludeGroup elements with Condition attribute MAY contain references to
216                         // properties and they will be expanded.
217                         var elements = EvaluatePropertiesAndImports (Xml.Children).ToArray (); // ToArray(): to not lazily evaluate elements.
218                         
219                         // next, evaluate items
220                         EvaluateItems (elements);
221                         
222                         // finally, evaluate targets and tasks
223                         EvaluateTargets (elements);
224                 }
225                 
226                 IEnumerable<ProjectElement> EvaluatePropertiesAndImports (IEnumerable<ProjectElement> elements)
227                 {
228                         // First step: evaluate Properties
229                         foreach (var child in elements) {
230                                 yield return child;
231                                 var pge = child as ProjectPropertyGroupElement;
232                                 if (pge != null && Evaluate (pge.Condition))
233                                         foreach (var p in pge.Properties)
234                                                 // do not allow overwriting reserved or well-known properties by user
235                                                 if (!this.properties.Any (_ => (_.IsReservedProperty || _.IsWellKnownProperty) && _.Name.Equals (p.Name, StringComparison.InvariantCultureIgnoreCase)))
236                                                         if (Evaluate (p.Condition))
237                                                                 this.properties.Add (new XmlProjectProperty (this, p, PropertyType.Normal, ProjectCollection.OngoingImports.Any ()));
238
239                                 var ige = child as ProjectImportGroupElement;
240                                 if (ige != null && Evaluate (ige.Condition)) {
241                                         foreach (var incc in ige.Imports) {
242                                                 if (Evaluate (incc.Condition))
243                                                         foreach (var e in Import (incc))
244                                                                 yield return e;
245                                         }
246                                 }
247                                 var inc = child as ProjectImportElement;
248                                 if (inc != null && Evaluate (inc.Condition))
249                                         foreach (var e in Import (inc))
250                                                 yield return e;
251                         }
252                 }
253                 
254                 internal IEnumerable<T> GetAllItems<T> (string include, string exclude, Func<string,T> creator, Func<string,ITaskItem> taskItemCreator, Func<string,bool> itemTypeCheck, Action<T,string> assignRecurse)
255                 {
256                         return ProjectCollection.GetAllItems<T> (ExpandString, include, exclude, creator, taskItemCreator, DirectoryPath, assignRecurse,
257                                 t => all_evaluated_items.Any (i => i.EvaluatedInclude == t.ItemSpec && itemTypeCheck (i.ItemType)));
258                 }
259
260                 void EvaluateItems (IEnumerable<ProjectElement> elements)
261                 {
262                         foreach (var child in elements) {
263                                 var ige = child as ProjectItemGroupElement;
264                                 if (ige != null) {
265                                         foreach (var p in ige.Items) {
266                                                 if (!Evaluate (ige.Condition) || !Evaluate (p.Condition))
267                                                         continue;
268                                                 Func<string,ProjectItem> creator = s => new ProjectItem (this, p, s);
269                                                 foreach (var item in GetAllItems<ProjectItem> (p.Include, p.Exclude, creator, s => new ProjectTaskItem (p, s), it => string.Equals (it, p.ItemType, StringComparison.OrdinalIgnoreCase), (t, s) => t.RecursiveDir = s)) {
270                                                         raw_items.Add (item);
271                                                         all_evaluated_items.Add (item);
272                                                 }
273                                         }
274                                 }
275                                 var def = child as ProjectItemDefinitionGroupElement;
276                                 if (def != null) {
277                                         foreach (var p in def.ItemDefinitions) {
278                                                 if (Evaluate (p.Condition)) {
279                                                         ProjectItemDefinition existing;
280                                                         if (!item_definitions.TryGetValue (p.ItemType, out existing))
281                                                                 item_definitions.Add (p.ItemType, (existing = new ProjectItemDefinition (this, p.ItemType)));
282                                                         existing.AddItems (p);
283                                                 }
284                                         }
285                                 }
286                         }
287                         all_evaluated_items.Sort ((p1, p2) => string.Compare (p1.ItemType, p2.ItemType, StringComparison.OrdinalIgnoreCase));
288                 }
289                 
290                 void EvaluateTargets (IEnumerable<ProjectElement> elements)
291                 {
292                         foreach (var child in elements) {
293                                 var te = child as ProjectTargetElement;
294                                 if (te != null)
295                                         // It overwrites same name target.
296                                         this.targets [te.Name] = new ProjectTargetInstance (te);
297                         }
298                 }
299                 
300                 IEnumerable<ProjectElement> Import (ProjectImportElement import)
301                 {
302                         string dir = ProjectCollection.GetEvaluationTimeThisFileDirectory (() => FullPath);
303                         string path = WindowsCompatibilityExtensions.FindMatchingPath (ExpandString (import.Project));
304                         path = Path.IsPathRooted (path) ? path : dir != null ? Path.Combine (dir, path) : Path.GetFullPath (path);
305                         if (ProjectCollection.OngoingImports.Contains (path)) {
306                                 switch (load_settings) {
307                                 case ProjectLoadSettings.RejectCircularImports:
308                                         throw new InvalidProjectFileException (import.Location, null, string.Format ("Circular imports was detected: {0} (resolved as \"{1}\") is already on \"importing\" stack", import.Project, path));
309                                 }
310                                 return new ProjectElement [0]; // do not import circular references
311                         }
312                         ProjectCollection.OngoingImports.Push (path);
313                         try {
314                                 using (var reader = XmlReader.Create (path)) {
315                                         var root = ProjectRootElement.Create (reader, ProjectCollection);
316                                         raw_imports.Add (new ResolvedImport (import, root, true));
317                                         return this.EvaluatePropertiesAndImports (root.Children).ToArray ();
318                                 }
319                         } finally {
320                                 ProjectCollection.OngoingImports.Pop ();
321                         }
322                 }
323
324                 public ICollection<ProjectItem> GetItemsIgnoringCondition (string itemType)
325                 {
326                         return new CollectionFromEnumerable<ProjectItem> (raw_items.Where (p => p.ItemType.Equals (itemType, StringComparison.OrdinalIgnoreCase)));
327                 }
328
329                 public void RemoveItems (IEnumerable<ProjectItem> items)
330                 {
331                         var removal = new List<ProjectItem> (items);
332                         foreach (var item in removal) {
333                                 var parent = item.Xml.Parent;
334                                 parent.RemoveChild (item.Xml);
335                                 if (parent.Count == 0)
336                                         parent.Parent.RemoveChild (parent);
337                         }
338                 }
339
340                 static readonly Dictionary<string, string> empty_metadata = new Dictionary<string, string> ();
341
342                 public IList<ProjectItem> AddItem (string itemType, string unevaluatedInclude)
343                 {
344                         return AddItem (itemType, unevaluatedInclude, empty_metadata);
345                 }
346
347                 public IList<ProjectItem> AddItem (string itemType, string unevaluatedInclude,
348                                 IEnumerable<KeyValuePair<string, string>> metadata)
349                 {
350                         // FIXME: needs several check that AddItemFast() does not process (see MSDN for details).
351
352                         return AddItemFast (itemType, unevaluatedInclude, metadata);
353                 }
354
355                 public IList<ProjectItem> AddItemFast (string itemType, string unevaluatedInclude)
356                 {
357                         return AddItemFast (itemType, unevaluatedInclude, empty_metadata);
358                 }
359
360                 public IList<ProjectItem> AddItemFast (string itemType, string unevaluatedInclude,
361                                                                      IEnumerable<KeyValuePair<string, string>> metadata)
362                 {
363                         throw new NotImplementedException ();
364                 }
365                 
366                 static readonly char [] target_sep = new char[] {';'};
367
368                 public bool Build ()
369                 {
370                         return Build (Xml.DefaultTargets.Split (target_sep, StringSplitOptions.RemoveEmptyEntries));
371                 }
372
373                 public bool Build (IEnumerable<ILogger> loggers)
374                 {
375                         return Build (Xml.DefaultTargets.Split (target_sep, StringSplitOptions.RemoveEmptyEntries), loggers);
376                 }
377
378                 public bool Build (string target)
379                 {
380                         return string.IsNullOrWhiteSpace (target) ? Build () : Build (new string [] {target});
381                 }
382
383                 public bool Build (string[] targets)
384                 {
385                         return Build (targets, new ILogger [0]);
386                 }
387
388                 public bool Build (ILogger logger)
389                 {
390                         return Build (Xml.DefaultTargets.Split (target_sep, StringSplitOptions.RemoveEmptyEntries), new ILogger [] {logger});
391                 }
392
393                 public bool Build (string[] targets, IEnumerable<ILogger> loggers)
394                 {
395                         return Build (targets, loggers, new ForwardingLoggerRecord [0]);
396                 }
397
398                 public bool Build (IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers)
399                 {
400                         return Build (Xml.DefaultTargets.Split (target_sep, StringSplitOptions.RemoveEmptyEntries), loggers, remoteLoggers);
401                 }
402
403                 public bool Build (string target, IEnumerable<ILogger> loggers)
404                 {
405                         return Build (new string [] { target }, loggers);
406                 }
407
408                 public bool Build (string[] targets, IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers)
409                 {
410                         // Unlike ProjectInstance.Build(), there is no place to fill outputs by targets, so ignore them
411                         // (i.e. we don't use the overload with output).
412                         //
413                         // This does not check FullPath, so don't call GetProjectInstanceForBuild() directly.
414                         return new BuildManager ().GetProjectInstanceForBuildInternal (this).Build (targets, loggers, remoteLoggers);
415                 }
416
417                 public bool Build (string target, IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers)
418                 {
419                         return Build (new string [] { target }, loggers, remoteLoggers);
420                 }
421
422                 public ProjectInstance CreateProjectInstance ()
423                 {
424                         var ret = new ProjectInstance (Xml, GlobalProperties, ToolsVersion, ProjectCollection);
425                         // FIXME: maybe fill other properties to the result.
426                         return ret;
427                 }
428                 
429                 bool Evaluate (string unexpandedValue)
430                 {
431                         return string.IsNullOrWhiteSpace (unexpandedValue) || new ExpressionEvaluator (this).EvaluateAsBoolean (unexpandedValue);
432                 }
433
434                 public string ExpandString (string unexpandedValue)
435                 {
436                         return WindowsCompatibilityExtensions.NormalizeFilePath (new ExpressionEvaluator (this).Evaluate (unexpandedValue));
437                 }
438
439                 public static string GetEvaluatedItemIncludeEscaped (ProjectItem item)
440                 {
441                         return ProjectCollection.Escape (item.EvaluatedInclude);
442                 }
443
444                 public static string GetEvaluatedItemIncludeEscaped (ProjectItemDefinition item)
445                 {
446                         // ?? ItemDefinition does not have Include attribute. What's the point here?
447                         throw new NotImplementedException ();
448                 }
449
450                 public ICollection<ProjectItem> GetItems (string itemType)
451                 {
452                         return new CollectionFromEnumerable<ProjectItem> (Items.Where (p => p.ItemType.Equals (itemType, StringComparison.OrdinalIgnoreCase)));
453                 }
454
455                 public ICollection<ProjectItem> GetItemsByEvaluatedInclude (string evaluatedInclude)
456                 {
457                         return new CollectionFromEnumerable<ProjectItem> (Items.Where (p => p.EvaluatedInclude.Equals (evaluatedInclude, StringComparison.OrdinalIgnoreCase)));
458                 }
459
460                 public IEnumerable<ProjectElement> GetLogicalProject ()
461                 {
462                         throw new NotImplementedException ();
463                 }
464
465                 public static string GetMetadataValueEscaped (ProjectMetadata metadatum)
466                 {
467                         return ProjectCollection.Escape (metadatum.EvaluatedValue);
468                 }
469
470                 public static string GetMetadataValueEscaped (ProjectItem item, string name)
471                 {
472                         var md = item.Metadata.FirstOrDefault (m => m.Name.Equals (name, StringComparison.OrdinalIgnoreCase));
473                         return md != null ? ProjectCollection.Escape (md.EvaluatedValue) : null;
474                 }
475
476                 public static string GetMetadataValueEscaped (ProjectItemDefinition item, string name)
477                 {
478                         var md = item.Metadata.FirstOrDefault (m => m.Name.Equals (name, StringComparison.OrdinalIgnoreCase));
479                         return md != null ? ProjectCollection.Escape (md.EvaluatedValue) : null;
480                 }
481
482                 public string GetPropertyValue (string name)
483                 {
484                         var prop = GetProperty (name);
485                         return prop != null ? prop.EvaluatedValue : string.Empty;
486                 }
487
488                 public static string GetPropertyValueEscaped (ProjectProperty property)
489                 {
490                         // WTF happens here.
491                         //return ProjectCollection.Escape (property.EvaluatedValue);
492                         return property.EvaluatedValue;
493                 }
494
495                 public ProjectProperty GetProperty (string name)
496                 {
497                         return properties.FirstOrDefault (p => p.Name.Equals (name, StringComparison.OrdinalIgnoreCase));
498                 }
499
500                 public void MarkDirty ()
501                 {
502                         if (!DisableMarkDirty)
503                                 is_dirty = true;
504                 }
505
506                 public void ReevaluateIfNecessary ()
507                 {
508                         throw new NotImplementedException ();
509                 }
510
511                 public bool RemoveGlobalProperty (string name)
512                 {
513                         throw new NotImplementedException ();
514                 }
515
516                 public bool RemoveItem (ProjectItem item)
517                 {
518                         throw new NotImplementedException ();
519                 }
520
521                 public bool RemoveProperty (ProjectProperty property)
522                 {
523                         var removed = properties.FirstOrDefault (p => p.Name.Equals (property.Name, StringComparison.OrdinalIgnoreCase));
524                         if (removed == null)
525                                 return false;
526                         properties.Remove (removed);
527                         return true;
528                 }
529
530                 public void Save ()
531                 {
532                         Xml.Save ();
533                 }
534
535                 public void Save (TextWriter writer)
536                 {
537                         Xml.Save (writer);
538                 }
539
540                 public void Save (string path)
541                 {
542                         Save (path, Encoding.Default);
543                 }
544
545                 public void Save (Encoding encoding)
546                 {
547                         Save (FullPath, encoding);
548                 }
549
550                 public void Save (string path, Encoding encoding)
551                 {
552                         using (var writer = new StreamWriter (path, false, encoding))
553                                 Save (writer);
554                 }
555
556                 public void SaveLogicalProject (TextWriter writer)
557                 {
558                         throw new NotImplementedException ();
559                 }
560
561                 public bool SetGlobalProperty (string name, string escapedValue)
562                 {
563                         throw new NotImplementedException ();
564                 }
565
566                 public ProjectProperty SetProperty (string name, string unevaluatedValue)
567                 {
568                         var p = new ManuallyAddedProjectProperty (this, name, unevaluatedValue);
569                         properties.Add (p);
570                         return p;
571                 }
572
573                 public ICollection<ProjectMetadata> AllEvaluatedItemDefinitionMetadata {
574                         get { throw new NotImplementedException (); }
575                 }
576
577                 public ICollection<ProjectItem> AllEvaluatedItems {
578                         get { return all_evaluated_items; }
579                 }
580
581                 public ICollection<ProjectProperty> AllEvaluatedProperties {
582                         get { return properties; }
583                 }
584
585                 public IDictionary<string, List<string>> ConditionedProperties {
586                         get {
587                                 // this property returns different instances every time.
588                                 var dic = new Dictionary<string, List<string>> ();
589                                 
590                                 // but I dunno HOW this evaluates
591                                 
592                                 throw new NotImplementedException ();
593                         }
594                 }
595
596                 public string DirectoryPath {
597                         get { return dir_path; }
598                 }
599
600                 public bool DisableMarkDirty { get; set; }
601
602                 public int EvaluationCounter {
603                         get { throw new NotImplementedException (); }
604                 }
605
606                 public string FullPath {
607                         get { return Xml.FullPath; }
608                         set { Xml.FullPath = value; }
609                 }
610                 
611                 class ResolvedImportComparer : IEqualityComparer<ResolvedImport>
612                 {
613                         public static ResolvedImportComparer Instance = new ResolvedImportComparer ();
614                         
615                         public bool Equals (ResolvedImport x, ResolvedImport y)
616                         {
617                                 return x.ImportedProject.FullPath.Equals (y.ImportedProject.FullPath);
618                         }
619                         public int GetHashCode (ResolvedImport obj)
620                         {
621                                 return obj.ImportedProject.FullPath.GetHashCode ();
622                         }
623                 }
624
625                 public IList<ResolvedImport> Imports {
626                         get { return raw_imports.Distinct (ResolvedImportComparer.Instance).ToList (); }
627                 }
628
629                 public IList<ResolvedImport> ImportsIncludingDuplicates {
630                         get { return raw_imports; }
631                 }
632
633                 public bool IsBuildEnabled {
634                         get { return ProjectCollection.IsBuildEnabled; }
635                 }
636
637                 bool is_dirty;
638                 public bool IsDirty {
639                         get { return is_dirty; }
640                 }
641
642                 public IDictionary<string, ProjectItemDefinition> ItemDefinitions {
643                         get { return item_definitions; }
644                 }
645
646                 [MonoTODO ("should be different from AllEvaluatedItems")]
647                 public ICollection<ProjectItem> Items {
648                         get { return AllEvaluatedItems; }
649                 }
650
651                 public ICollection<ProjectItem> ItemsIgnoringCondition {
652                         get { return raw_items; }
653                 }
654
655                 public ICollection<string> ItemTypes {
656                         get { return new CollectionFromEnumerable<string> (raw_items.Select (i => i.ItemType).Distinct ()); }
657                 }
658
659                 [MonoTODO ("should be different from AllEvaluatedProperties")]
660                 public ICollection<ProjectProperty> Properties {
661                         get { return AllEvaluatedProperties; }
662                 }
663
664                 public bool SkipEvaluation { get; set; }
665
666                 #if NET_4_5
667                 public
668                 #else
669                 internal
670                 #endif
671                 IDictionary<string, ProjectTargetInstance> Targets {
672                         get { return targets; }
673                 }
674                 
675                 // These are required for reserved property, represents dynamically changing property values.
676                 // This should resolve to either the project file path or that of the imported file.
677                 internal string GetEvaluationTimeThisFileDirectory ()
678                 {
679                         var file = GetEvaluationTimeThisFile ();
680                         var dir = Path.IsPathRooted (file) ? Path.GetDirectoryName (file) : Directory.GetCurrentDirectory ();
681                         return dir + Path.DirectorySeparatorChar;
682                 }
683
684                 internal string GetEvaluationTimeThisFile ()
685                 {
686                         return ProjectCollection.OngoingImports.Count > 0 ? ProjectCollection.OngoingImports.Peek () : FullPath ?? string.Empty;
687                 }
688                 
689                 internal string GetFullPath (string pathRelativeToProject)
690                 {
691                         if (Path.IsPathRooted (pathRelativeToProject))
692                                 return pathRelativeToProject;
693                         return Path.GetFullPath (Path.Combine (DirectoryPath, pathRelativeToProject));
694                 }
695         }
696 }