Merge pull request #1079 from esdrubal/webclient_cancel
[mono.git] / mcs / class / Microsoft.Build / Microsoft.Build.Execution / ProjectInstance.cs
1 //
2 // ProjectInstance.cs
3 //
4 // Author:
5 //   Rolf Bjarne Kvinge (rolf@xamarin.com)
6 //   Atsushi Enomoto (atsushi@xamarin.com)
7 //
8 // Copyright (C) 2011,2013 Xamarin Inc.
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.Collections;
32 using System.Collections.Generic;
33 using System.Linq;
34
35 using Microsoft.Build.Construction;
36 using Microsoft.Build.Evaluation;
37 using Microsoft.Build.Framework;
38 using Microsoft.Build.Internal.Expressions;
39 using Microsoft.Build.Logging;
40
41 //
42 // It is not always consistent to reuse Project and its evaluation stuff mostly because
43 // both BuildParameters.ctor() and Project.ctor() takes arbitrary ProjectCollection, which are not very likely eqivalent
44 // (as BuildParameters.ctor(), unlike Project.ctor(...), is known to create a new ProjectCollection instance).
45 //
46 // However, that inconsistency could happen even if you only use ProjectInstance and BuildParameters.
47 // They both have constructors that take ProjectCollection and there is no guarantee that the arguments are the same.
48 // BuildManager.Build() does not fail because of inconsistent ProjectCollection instance on .NET.
49 //
50 // Anyhow, I'm not going to instantiate Project within ProjectInstance code for another reason:
51 // ProjectCollection.GetLoadedProject() does not return any Project instnace for corresponding ProjectInstance
52 // (or I should say, ProjectRootElement for both).
53 using Microsoft.Build.Internal;
54 using System.Xml;
55 using Microsoft.Build.Exceptions;
56 using System.IO;
57
58
59 namespace Microsoft.Build.Execution
60 {
61         public class ProjectInstance
62         {
63                 // instance members
64                 
65                 public ProjectInstance (ProjectRootElement xml)
66                         : this (xml, null, null, ProjectCollection.GlobalProjectCollection)
67                 {
68                 }
69
70                 public ProjectInstance (string projectFile)
71                         : this (projectFile, null, null, ProjectCollection.GlobalProjectCollection)
72                 {
73                 }
74
75                 public ProjectInstance (string projectFile, IDictionary<string, string> globalProperties,
76                                 string toolsVersion)
77                         : this (projectFile, globalProperties, toolsVersion, ProjectCollection.GlobalProjectCollection)
78                 {
79                 }
80
81                 public ProjectInstance (ProjectRootElement xml, IDictionary<string, string> globalProperties,
82                                 string toolsVersion, ProjectCollection projectCollection)
83                 {
84                         projects = projectCollection;
85                         global_properties = globalProperties ?? new Dictionary<string, string> ();
86                         tools_version = !string.IsNullOrEmpty (toolsVersion) ? toolsVersion :
87                                 !string.IsNullOrEmpty (xml.ToolsVersion) ? xml.ToolsVersion :
88                                 projects.DefaultToolsVersion;
89                         InitializeProperties (xml);
90                 }
91
92                 public ProjectInstance (string projectFile, IDictionary<string, string> globalProperties,
93                                 string toolsVersion, ProjectCollection projectCollection)
94                         : this (ProjectRootElement.Create (projectFile), globalProperties, toolsVersion, projectCollection)
95                 {
96                 }
97
98                 ProjectCollection projects;
99                 IDictionary<string, string> global_properties;
100                 
101                 string full_path, directory;
102                 #if NET_4_5
103                 ElementLocation location;
104                 #endif
105                 
106                 Dictionary<string, ProjectItemDefinitionInstance> item_definitions;
107                 List<ResolvedImport> raw_imports; // maybe we don't need this...
108                 List<ProjectItemInstance> all_evaluated_items;
109                 List<ProjectItemInstance> raw_items;
110                 Dictionary<string,ProjectPropertyInstance> properties;
111                 Dictionary<string, ProjectTargetInstance> targets;
112                 string tools_version;
113                 
114                 // FIXME: this is a duplicate code between Project and ProjectInstance
115                 string [] GetDefaultTargets (ProjectRootElement xml)
116                 {
117                         var ret = GetDefaultTargets (xml, true, true);
118                         return ret.Any () ? ret : GetDefaultTargets (xml, false, true);
119                 }
120                 
121                 string [] GetDefaultTargets (ProjectRootElement xml, bool fromAttribute, bool checkImports)
122                 {
123                         if (fromAttribute) {
124                                 var ret = xml.DefaultTargets.Split (item_target_sep, StringSplitOptions.RemoveEmptyEntries).Select (s => s.Trim ()).ToArray ();
125                                 if (checkImports && ret.Length == 0) {
126                                         foreach (var imp in this.raw_imports) {
127                                                 ret = GetDefaultTargets (imp.ImportedProject, true, false);
128                                                 if (ret.Any ())
129                                                         break;
130                                         }
131                                 }
132                                 return ret;
133                         } else {
134                                 if (xml.Targets.Any ())
135                                         return new String [] { xml.Targets.First ().Name };
136                                 if (checkImports) {
137                                         foreach (var imp in this.raw_imports) {
138                                                 var ret = GetDefaultTargets (imp.ImportedProject, false, false);
139                                                 if (ret.Any ())
140                                                         return ret;
141                                         }
142                                 }
143                                 return new string [0];
144                         }
145                 }
146
147                 void InitializeProperties (ProjectRootElement xml)
148                 {
149                         #if NET_4_5
150                         location = xml.Location;
151                         #endif
152                         full_path = xml.FullPath;
153                         directory = string.IsNullOrWhiteSpace (xml.DirectoryPath) ? System.IO.Directory.GetCurrentDirectory () : xml.DirectoryPath;
154                         InitialTargets = xml.InitialTargets.Split (item_target_sep, StringSplitOptions.RemoveEmptyEntries).Select (s => s.Trim ()).ToList ();
155
156                         raw_imports = new List<ResolvedImport> ();
157                         item_definitions = new Dictionary<string, ProjectItemDefinitionInstance> ();
158                         targets = new Dictionary<string, ProjectTargetInstance> ();
159                         raw_items = new List<ProjectItemInstance> ();
160                         
161                         properties = new Dictionary<string,ProjectPropertyInstance> ();
162                 
163                         foreach (DictionaryEntry p in Environment.GetEnvironmentVariables ())
164                                 // FIXME: this is kind of workaround for unavoidable issue that PLATFORM=* is actually given
165                                 // on some platforms and that prevents setting default "PLATFORM=AnyCPU" property.
166                                 if (!string.Equals ("PLATFORM", (string) p.Key, StringComparison.OrdinalIgnoreCase))
167                                         this.properties [(string) p.Key] = new ProjectPropertyInstance ((string) p.Key, true, (string) p.Value);
168                         foreach (var p in global_properties)
169                                 this.properties [p.Key] = new ProjectPropertyInstance (p.Key, false, p.Value);
170                         var tools = projects.GetToolset (tools_version) ?? projects.GetToolset (projects.DefaultToolsVersion);
171                         foreach (var p in projects.GetReservedProperties (tools, this, xml))
172                                 this.properties [p.Name] = p;
173                         foreach (var p in ProjectCollection.GetWellKnownProperties (this))
174                                 this.properties [p.Name] = p;
175
176                         ProcessXml (xml);
177                         
178                         DefaultTargets = GetDefaultTargets (xml).ToList ();
179                 }
180                 
181                 static readonly char [] item_target_sep = {';'};
182                 
183                 void ProcessXml (ProjectRootElement xml)
184                 {
185                         UsingTasks = new List<ProjectUsingTaskElement> ();
186                         
187                         // this needs to be initialized here (regardless of that items won't be evaluated at property evaluation;
188                         // Conditions could incorrectly reference items and lack of this list causes NRE.
189                         all_evaluated_items = new List<ProjectItemInstance> ();
190
191                         // property evaluation happens couple of times.
192                         // At first step, all non-imported properties are evaluated TOO, WHILE those properties are being evaluated.
193                         // This means, Include and IncludeGroup elements with Condition attribute MAY contain references to
194                         // properties and they will be expanded.
195                         var elements = EvaluatePropertiesAndUsingTasksAndImportsAndChooses (xml.Children).ToArray (); // ToArray(): to not lazily evaluate elements.
196                         
197                         // next, evaluate items
198                         EvaluateItems (xml, elements);
199                         
200                         // finally, evaluate targets and tasks
201                         EvaluateTargets (elements);
202                 }
203                 
204                 IEnumerable<ProjectElement> EvaluatePropertiesAndUsingTasksAndImportsAndChooses (IEnumerable<ProjectElement> elements)
205                 {
206                         foreach (var child in elements) {
207                                 yield return child;
208                                 
209                                 var ute = child as ProjectUsingTaskElement;
210                                 if (ute != null && EvaluateCondition (ute.Condition))
211                                         UsingTasks.Add (ute);
212                                 
213                                 var pge = child as ProjectPropertyGroupElement;
214                                 if (pge != null && EvaluateCondition (pge.Condition))
215                                         foreach (var p in pge.Properties)
216                                                 // do not allow overwriting reserved or well-known properties by user
217                                                 if (!this.properties.Any (_ => (_.Value.IsImmutable) && _.Key.Equals (p.Name, StringComparison.InvariantCultureIgnoreCase)))
218                                                         if (EvaluateCondition (p.Condition))
219                                                                 this.properties [p.Name] = new ProjectPropertyInstance (p.Name, false, ExpandString (p.Value));
220
221                                 var ige = child as ProjectImportGroupElement;
222                                 if (ige != null && EvaluateCondition (ige.Condition)) {
223                                         foreach (var incc in ige.Imports) {
224                                                 if (EvaluateCondition (incc.Condition))
225                                                         foreach (var e in Import (incc))
226                                                                 yield return e;
227                                         }
228                                 }
229                                 
230                                 var inc = child as ProjectImportElement;
231                                 if (inc != null && EvaluateCondition (inc.Condition))
232                                         foreach (var e in Import (inc))
233                                                 yield return e;
234                                 var choose = child as ProjectChooseElement;
235                                 if (choose != null && EvaluateCondition (choose.Condition)) {
236                                         bool done = false;
237                                         foreach (ProjectWhenElement when in choose.WhenElements)
238                                                 if (EvaluateCondition (when.Condition)) {
239                                                         foreach (var e in EvaluatePropertiesAndUsingTasksAndImportsAndChooses (when.Children))
240                                                                 yield return e;
241                                                         done = true;
242                                                         break;
243                                                 }
244                                         if (!done && choose.OtherwiseElement != null)
245                                                 foreach (var e in EvaluatePropertiesAndUsingTasksAndImportsAndChooses (choose.OtherwiseElement.Children))
246                                                         yield return e;
247                                 }
248                         }
249                 }
250                 
251                 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)
252                 {
253                         return ProjectCollection.GetAllItems<T> (ExpandString, include, exclude, creator, taskItemCreator, Directory, assignRecurse,
254                                 t => all_evaluated_items.Any (i => i.EvaluatedInclude == t.ItemSpec && itemTypeCheck (i.ItemType)));
255                 }
256
257                 void EvaluateItems (ProjectRootElement xml, IEnumerable<ProjectElement> elements)
258                 {
259                         foreach (var child in elements.Reverse ()) {
260                                 var ige = child as ProjectItemGroupElement;
261                                 if (ige != null) {
262                                         foreach (var p in ige.Items) {
263                                                 if (!EvaluateCondition (ige.Condition) || !EvaluateCondition (p.Condition))
264                                                         continue;
265                                                 Func<string,ProjectItemInstance> creator = s => new ProjectItemInstance (this, p.ItemType, p.Metadata.Select (m => new KeyValuePair<string,string> (m.Name, m.Value)).ToList (), s);
266                                                 foreach (var item in GetAllItems (p.Include, p.Exclude, creator, s => new ProjectTaskItem (p, s), it => string.Equals (it, p.ItemType, StringComparison.OrdinalIgnoreCase), (t, s) => t.RecursiveDir = s)) {
267                                                         raw_items.Add (item);
268                                                         all_evaluated_items.Add (item);
269                                                 }
270                                         }
271                                 }
272                                 var def = child as ProjectItemDefinitionGroupElement;
273                                 if (def != null) {
274                                         foreach (var p in def.ItemDefinitions) {
275                                                 if (EvaluateCondition (p.Condition)) {
276                                                         ProjectItemDefinitionInstance existing;
277                                                         if (!item_definitions.TryGetValue (p.ItemType, out existing))
278                                                                 item_definitions.Add (p.ItemType, (existing = new ProjectItemDefinitionInstance (p)));
279                                                         existing.AddItems (p);
280                                                 }
281                                         }
282                                 }
283                         }
284                         all_evaluated_items.Sort ((p1, p2) => string.Compare (p1.ItemType, p2.ItemType, StringComparison.OrdinalIgnoreCase));
285                 }
286                 
287                 void EvaluateTargets (IEnumerable<ProjectElement> elements)
288                 {
289                         foreach (var child in elements) {
290                                 var te = child as ProjectTargetElement;
291                                 if (te != null)
292                                         // It overwrites same name target.
293                                         this.targets [te.Name] = new ProjectTargetInstance (te);
294                         }
295                 }
296                 
297                 IEnumerable<ProjectElement> Import (ProjectImportElement import)
298                 {
299                         string dir = projects.GetEvaluationTimeThisFileDirectory (() => FullPath);
300                         // FIXME: use appropriate logger (but cannot be instantiated here...?)
301                         string path = ProjectCollection.FindFileInSeveralExtensionsPath (ref extensions_path_override, ExpandString, import.Project, TextWriter.Null.WriteLine);
302                         path = Path.IsPathRooted (path) ? path : dir != null ? Path.Combine (dir, path) : Path.GetFullPath (path);
303                         if (projects.OngoingImports.Contains (path))
304                                 throw new InvalidProjectFileException (import.Location, null, string.Format ("Circular imports was detected: {0} is already on \"importing\" stack", path));
305                         projects.OngoingImports.Push (path);
306                         try {
307                                 using (var reader = XmlReader.Create (path)) {
308                                         var root = ProjectRootElement.Create (reader, projects);
309                                         raw_imports.Add (new ResolvedImport (import, root, true));
310                                         return this.EvaluatePropertiesAndUsingTasksAndImportsAndChooses (root.Children).ToArray ();
311                                 }
312                         } finally {
313                                 projects.OngoingImports.Pop ();
314                         }
315                 }
316
317                 internal IEnumerable<ProjectItemInstance> AllEvaluatedItems {
318                         get { return all_evaluated_items; }
319                 }
320
321                 public List<string> DefaultTargets { get; private set; }
322                 
323                 public string Directory {
324                         get { return directory; }
325                 }
326                 
327                 public string FullPath {
328                         get { return full_path; }
329                 }
330                 
331                 public IDictionary<string, string> GlobalProperties {
332                         get { return global_properties; }
333                 }
334                 
335                 public List<string> InitialTargets { get; private set; }
336                 
337 #if NET_4_5             
338                 public bool IsImmutable {
339                         get { throw new NotImplementedException (); }
340                 }
341 #endif
342                 
343                 public IDictionary<string, ProjectItemDefinitionInstance> ItemDefinitions {
344                         get { return item_definitions; }
345                 }
346                 
347                 public ICollection<ProjectItemInstance> Items {
348                         get { return all_evaluated_items; }
349                 }
350                 
351                 public ICollection<string> ItemTypes {
352                         get { return all_evaluated_items.Select (i => i.ItemType).Distinct ().ToArray (); }
353                 }
354
355 #if NET_4_5             
356                 public ElementLocation ProjectFileLocation {
357                         get { return location; }
358                 }
359 #endif
360
361                 public ICollection<ProjectPropertyInstance> Properties {
362                         get { return properties.Values; }
363                 }
364                 
365                 #if NET_4_5
366                 public
367                 #else
368                 internal
369                 #endif
370                 IDictionary<string, ProjectTargetInstance> Targets {
371                         get { return targets; }
372                 }
373                 
374                 public string ToolsVersion {
375                         get { return tools_version; }
376                 }
377
378                 public ProjectItemInstance AddItem (string itemType, string evaluatedInclude)
379                 {
380                         return AddItem (itemType, evaluatedInclude, new KeyValuePair<string, string> [0]);
381                 }
382                 
383                 public ProjectItemInstance AddItem (string itemType, string evaluatedInclude, IEnumerable<KeyValuePair<string, string>> metadata)
384                 {
385                         var item = new ProjectItemInstance (this, itemType, metadata, evaluatedInclude);
386                         raw_items.Add (item);
387                         all_evaluated_items.Add (item);
388                         return item;
389                 }
390
391                 public bool Build ()
392                 {
393                         return Build (new ILogger [0]);
394                 }
395
396                 public bool Build (IEnumerable<ILogger> loggers)
397                 {
398                         return Build (loggers, new ForwardingLoggerRecord [0]);
399                 }
400                 
401                 public bool Build (IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers)
402                 {
403                         return Build (DefaultTargets.ToArray (), loggers, remoteLoggers);
404                 }
405
406                 public bool Build (string target, IEnumerable<ILogger> loggers)
407                 {
408                         return Build (target, loggers, new ForwardingLoggerRecord [0]);
409                 }
410
411                 public bool Build (string [] targets, IEnumerable<ILogger> loggers)
412                 {
413                         return Build (targets, loggers, new ForwardingLoggerRecord [0]);
414                 }
415                 
416                 public bool Build (string target, IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers)
417                 {
418                         return Build (new string [] {target}, loggers, remoteLoggers);
419                 }
420                 
421                 public bool Build (string [] targets, IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers)
422                 {
423                         IDictionary<string, TargetResult> outputs;
424                         return Build (targets, loggers, remoteLoggers, out outputs);
425                 }
426
427                 public bool Build (string[] targets, IEnumerable<ILogger> loggers, out IDictionary<string, TargetResult> targetOutputs)
428                 {
429                         return Build (targets, loggers, new ForwardingLoggerRecord [0], out targetOutputs);
430                 }
431
432                 public bool Build (string[] targets, IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers, out IDictionary<string, TargetResult> targetOutputs)
433                 {
434                         var manager = new BuildManager ();
435                         var parameters = new BuildParameters (projects) {
436                                 ForwardingLoggers = remoteLoggers,
437                                 Loggers = loggers,
438                                 DefaultToolsVersion = projects.DefaultToolsVersion,
439                         };
440                         var requestData = new BuildRequestData (this, targets ?? DefaultTargets.ToArray ());
441                         var result = manager.Build (parameters, requestData);
442                         targetOutputs = result.ResultsByTarget;
443                         return result.OverallResult == BuildResultCode.Success;
444                 }
445                 
446                 public ProjectInstance DeepCopy ()
447                 {
448                         return DeepCopy (false);
449                 }
450                 
451                 public ProjectInstance DeepCopy (bool isImmutable)
452                 {
453                         throw new NotImplementedException ();
454                 }
455                 
456                 public bool EvaluateCondition (string condition)
457                 {
458                         return string.IsNullOrWhiteSpace (condition) || new ExpressionEvaluator (this).EvaluateAsBoolean (condition);
459                 }
460
461                 public string ExpandString (string unexpandedValue)
462                 {
463                         return WindowsCompatibilityExtensions.NormalizeFilePath (new ExpressionEvaluator (this).Evaluate (unexpandedValue));
464                 }
465
466                 internal string ExpandString (ExpressionEvaluator evaluator, string unexpandedValue)
467                 {
468                         return WindowsCompatibilityExtensions.NormalizeFilePath (evaluator.Evaluate (unexpandedValue));
469                 }
470
471                 public ICollection<ProjectItemInstance> GetItems (string itemType)
472                 {
473                         return new CollectionFromEnumerable<ProjectItemInstance> (Items.Where (p => p.ItemType.Equals (itemType, StringComparison.OrdinalIgnoreCase)));
474                 }
475
476                 public IEnumerable<ProjectItemInstance> GetItemsByItemTypeAndEvaluatedInclude (string itemType, string evaluatedInclude)
477                 {
478                         throw new NotImplementedException ();
479                 }
480
481                 string extensions_path_override;
482
483                 public ProjectPropertyInstance GetProperty (string name)
484                 {
485                         if (extensions_path_override != null && (name.Equals ("MSBuildExtensionsPath") || name.Equals ("MSBuildExtensionsPath32") || name.Equals ("MSBuildExtensionsPath64")))
486                                 return new ProjectPropertyInstance (name, true, extensions_path_override);
487                         return properties.Values.FirstOrDefault (p => p.Name.Equals (name, StringComparison.OrdinalIgnoreCase));
488                 }
489                 
490                 public string GetPropertyValue (string name)
491                 {
492                         var prop = GetProperty (name);
493                         return prop != null ? prop.EvaluatedValue : string.Empty;
494                 }
495                 
496                 public bool RemoveItem (ProjectItemInstance item)
497                 {
498                         // yeah, this raw_items should vanish...
499                         raw_items.Remove (item);
500                         return all_evaluated_items.Remove (item);
501                 }
502
503                 public bool RemoveProperty (string name)
504                 {
505                         var removed = properties.Values.FirstOrDefault (p => p.Name.Equals (name, StringComparison.OrdinalIgnoreCase));
506                         if (removed == null)
507                                 return false;
508                         properties.Remove (name);
509                         return true;
510                 }
511                 
512                 public ProjectPropertyInstance SetProperty (string name, string evaluatedValue)
513                 {
514                         var p = new ProjectPropertyInstance (name, false, evaluatedValue);
515                         properties [p.Name] = p;
516                         return p;
517                 }
518                 
519                 public ProjectRootElement ToProjectRootElement ()
520                 {
521                         throw new NotImplementedException ();
522                 }
523                 
524 #if NET_4_5
525                 public void UpdateStateFrom (ProjectInstance projectState)
526                 {
527                         throw new NotImplementedException ();
528                 }
529 #endif
530                 
531                 // static members               
532
533                 public static string GetEvaluatedItemIncludeEscaped (ProjectItemDefinitionInstance item)
534                 {
535                         // ?? ItemDefinition does not have Include attribute. What's the point here?
536                         throw new NotImplementedException ();
537                 }
538
539                 public static string GetEvaluatedItemIncludeEscaped (ProjectItemInstance item)
540                 {
541                         return ProjectCollection.Escape (item.EvaluatedInclude);
542                 }
543
544                 public static string GetMetadataValueEscaped (ProjectMetadataInstance metadatum)
545                 {
546                         return ProjectCollection.Escape (metadatum.EvaluatedValue);
547                 }
548                 
549                 public static string GetMetadataValueEscaped (ProjectItemDefinitionInstance item, string name)
550                 {
551                         var md = item.Metadata.FirstOrDefault (m => m.Name.Equals (name, StringComparison.OrdinalIgnoreCase));
552                         return md != null ? ProjectCollection.Escape (md.EvaluatedValue) : null;
553                 }
554                 
555                 public static string GetMetadataValueEscaped (ProjectItemInstance item, string name)
556                 {
557                         var md = item.Metadata.FirstOrDefault (m => m.Name.Equals (name, StringComparison.OrdinalIgnoreCase));
558                         return md != null ? ProjectCollection.Escape (md.EvaluatedValue) : null;
559                 }
560
561                 public static string GetPropertyValueEscaped (ProjectPropertyInstance property)
562                 {
563                         // WTF happens here.
564                         //return ProjectCollection.Escape (property.EvaluatedValue);
565                         return property.EvaluatedValue;
566                 }
567
568                 internal List<ProjectUsingTaskElement> UsingTasks { get; private set; }
569                 
570                 internal string GetFullPath (string pathRelativeToProject)
571                 {
572                         if (Path.IsPathRooted (pathRelativeToProject))
573                                 return pathRelativeToProject;
574                         return Path.GetFullPath (Path.Combine (Directory, pathRelativeToProject));
575                 }
576         }
577 }
578