Add support for resolving project and other assembly references, including
[mono.git] / mcs / class / Microsoft.Build.Engine / Test / Microsoft.Build.BuildEngine / ProjectTest.cs
1 //
2 // ProjectTest.cs:
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 //
7 // (C) 2005 Marek Sieradzki
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 using System;
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.IO;
32 using System.Xml;
33 using Microsoft.Build.BuildEngine;
34 using Microsoft.Build.Framework;
35 using Microsoft.Build.Utilities;
36 using NUnit.Framework;
37 using System.Text;
38
39 using MBT = MonoTests.Microsoft.Build.Tasks;
40
41 namespace MonoTests.Microsoft.Build.BuildEngine {
42
43         class TestLogger : Logger {
44                 int target_started_events = 0;
45                 int target_finished_events = 0;
46
47                 public override void Initialize (IEventSource eventSource)
48                 {
49                         eventSource.TargetStarted += new TargetStartedEventHandler(TargetStarted);
50                         eventSource.TargetFinished += new TargetFinishedEventHandler(TargetFinished);
51                         eventSource.MessageRaised += new BuildMessageEventHandler(Message);
52                         eventSource.WarningRaised += new BuildWarningEventHandler(Warning);
53                 }
54
55                 void TargetStarted (object sender, TargetStartedEventArgs args)
56                 {
57                         target_started_events++;
58                 }
59
60                 void TargetFinished (object sender, TargetFinishedEventArgs args)
61                 {
62                         target_finished_events++;
63                 }
64
65                 void Message (object sender, BuildMessageEventArgs args)
66                 {
67                 }
68                 
69                 void Warning (object sender, BuildWarningEventArgs args)
70                 {
71                 }
72
73                 public int TargetStartedEvents { get { return target_started_events; } }
74
75                 public int TargetFinishedEvents { get { return target_finished_events; } }
76         }
77
78         [TestFixture]
79         public class ProjectTest {
80
81                 /*
82                 Import [] GetImports (ImportCollection ic)
83                 {
84                         List<Import> list = new List<Import> ();
85                         foreach (Import i in ic)
86                                 list.Add (i);
87                         return list.ToArray ();
88                 }
89                 */
90
91                 [Test]
92                 public void TestAssignment1 ()
93                 {
94                         Engine engine;
95                         Project project;
96                         string documentString =
97                                 "<Project></Project>";
98                         
99                         engine = new Engine (Consts.BinPath);
100                         DateTime time = DateTime.Now;
101                         project = engine.CreateNewProject ();
102                         try {
103                                 project.LoadXml (documentString);
104                         } catch (InvalidProjectFileException) {
105                                 Assert.AreEqual (true, project.BuildEnabled, "A1");
106                                 Assert.AreEqual (String.Empty, project.DefaultTargets, "A2");
107                                 Assert.AreEqual (String.Empty, project.FullFileName, "A3");
108                                 Assert.AreEqual (false, project.IsDirty, "A4");
109                                 Assert.AreEqual (false, project.IsValidated, "A5");
110                                 Assert.AreEqual (engine, project.ParentEngine, "A6");
111                                 Console.WriteLine ("time: {0} p.t: {1}", time, project.TimeOfLastDirty);
112                                 Assert.IsTrue (time <= project.TimeOfLastDirty, "A7");
113                                 Assert.IsTrue (String.Empty != project.Xml, "A8");
114                                 return;
115                         }
116
117                         Assert.Fail ("Expected InvalidProjectFileException");
118                 }
119
120                 [Test]
121                 public void TestAssignment2 ()
122                 {
123                         Engine engine;
124                         Project project;
125                         string documentString =
126                                 "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"></Project>";
127                         
128                         engine = new Engine (Consts.BinPath);
129                         DateTime time = DateTime.Now;
130                         project = engine.CreateNewProject ();
131                         project.LoadXml (documentString);
132
133                         Assert.AreEqual (true, project.BuildEnabled, "A1");
134                         Assert.AreEqual (String.Empty, project.DefaultTargets, "A2");
135                         Assert.AreEqual (String.Empty, project.FullFileName, "A3");
136                         Assert.AreEqual (true, project.IsDirty, "A4");
137                         Assert.AreEqual (false, project.IsValidated, "A5");
138                         Assert.AreEqual (engine, project.ParentEngine, "A6");
139                         Assert.IsTrue (time <= project.TimeOfLastDirty, "A7");
140                         Assert.IsTrue (String.Empty != project.Xml, "A8");
141                 }
142
143                 [Test]
144                 [Category ("NotWorking")]
145                 public void TestAddNewImport1 ()
146                 {
147                         Engine engine;
148                         Project project;
149
150                         string documentString = @"
151                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
152                                         <PropertyGroup />
153                                         <ItemGroup />
154                                         <Target Name='a' />
155                                         <Import Project='Test/resources/Import.csproj' />
156                                 </Project>
157                         ";
158
159                         engine = new Engine (Consts.BinPath);
160                         project = engine.CreateNewProject ();
161                         project.LoadXml (documentString);
162
163                         project.AddNewImport ("a", "true");
164                         // reevaluation wasn't caused by anything so it has only old import
165                         Assert.AreEqual (1, project.Imports.Count, "A1");
166                 }
167
168                 [Test]
169                 [Ignore ("Too detailed probably (implementation specific)")]
170                 public void TestAddNewItem1 ()
171                 {
172                         Engine engine;
173                         Project project;
174                         BuildItemGroup [] groups = new BuildItemGroup [1];
175
176                         string documentString = @"
177                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
178                                 </Project>
179                         ";
180
181                         engine = new Engine (Consts.BinPath);
182                         project = engine.CreateNewProject ();
183                         project.LoadXml (documentString);
184
185                         BuildItem item = project.AddNewItem ("A", "B");
186
187                         Assert.AreEqual (1, project.ItemGroups.Count, "A1");
188                         project.ItemGroups.CopyTo (groups, 0);
189                         Assert.AreEqual (1, groups [0].Count, "A2");
190                         Assert.AreEqual ("B", groups [0] [0].Include, "A3");
191                         Assert.AreEqual ("B", groups [0] [0].FinalItemSpec, "A4");
192                         Assert.AreEqual ("A", groups [0] [0].Name, "A5");
193                         //Assert.AreNotSame (item, groups [0] [0], "A6");
194                         Assert.IsFalse (object.ReferenceEquals (item, groups [0] [0]), "A6");
195
196                         Assert.AreEqual (1, project.EvaluatedItems.Count, "A7");
197                         Assert.AreEqual ("B", project.EvaluatedItems [0].Include, "A8");
198                         Assert.AreEqual ("B", project.EvaluatedItems [0].FinalItemSpec, "A9");
199                         Assert.AreEqual ("A", project.EvaluatedItems [0].Name, "A10");
200                         //Assert.AreNotSame (item, project.EvaluatedItems [0], "A11");
201                         Assert.IsFalse (object.ReferenceEquals (item, project.EvaluatedItems [0]), "A11");
202                 }
203
204                 [Test]
205                 [Category ("NotWorking")]
206                 public void TestAddNewItem2 ()
207                 {
208                         Engine engine;
209                         Project project;
210
211                         engine = new Engine (Consts.BinPath);
212                         project = engine.CreateNewProject ();
213
214                         BuildItem item = project.AddNewItem ("A", "a;b;c");
215                         Assert.AreEqual ("a;b;c", item.Include, "A1");
216                         Assert.AreEqual ("a", item.FinalItemSpec, "A2");
217
218                         Assert.AreEqual (3, project.EvaluatedItems.Count, "A3");
219                 }
220
221                 [Test]
222                 public void TestAddNewItem3 ()
223                 {
224                         Engine engine;
225                         Project project;
226                         BuildItemGroup [] groups = new BuildItemGroup [4];
227
228                         string documentString = @"
229                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
230                                         <ItemGroup />
231                                         <ItemGroup>
232                                                 <A Include='a'/>
233                                         </ItemGroup>
234                                         <ItemGroup>
235                                                 <B Include='a'/>
236                                         </ItemGroup>
237                                         <ItemGroup>
238                                                 <B Include='a'/>
239                                         </ItemGroup>
240                                 </Project>
241                         ";
242
243                         engine = new Engine (Consts.BinPath);
244                         project = engine.CreateNewProject ();
245                         project.LoadXml (documentString);
246
247                         project.AddNewItem ("B", "b");
248
249                         project.ItemGroups.CopyTo (groups, 0);
250                         Assert.AreEqual (0, groups [0].Count, "A1");
251                         Assert.AreEqual (1, groups [1].Count, "A2");
252                         Assert.AreEqual (1, groups [2].Count, "A3");
253                         Assert.AreEqual (2, groups [3].Count, "A4");
254                 }
255                 [Test]
256                 public void TestAddNewItemGroup ()
257                 {
258                         Engine engine;
259                         Project project;
260
261                         string documentString = @"
262                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
263                                 </Project>
264                         ";
265
266                         engine = new Engine (Consts.BinPath);
267                         project = engine.CreateNewProject ();
268                         project.LoadXml (documentString);
269
270                         BuildItemGroup big = project.AddNewItemGroup ();
271                         Assert.IsNotNull (big, "A1");
272                         Assert.AreEqual (String.Empty, big.Condition, "A2");
273                         Assert.AreEqual (0, big.Count, "A3");
274                         Assert.AreEqual (false, big.IsImported, "A4");
275                         Assert.IsTrue (project.IsDirty, "A5");
276                 }
277
278                 [Test]
279                 public void TestAddNewPropertyGroup ()
280                 {
281                         Engine engine;
282                         Project project;
283
284                         string documentString = @"
285                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
286                                 </Project>
287                         ";
288
289                         engine = new Engine (Consts.BinPath);
290                         project = engine.CreateNewProject ();
291                         project.LoadXml (documentString);
292
293                         BuildPropertyGroup bpg = project.AddNewPropertyGroup (false);
294                         Assert.IsNotNull (bpg, "A1");
295                         Assert.AreEqual (String.Empty, bpg.Condition, "A2");
296                         Assert.AreEqual (0, bpg.Count, "A3");
297                         Assert.AreEqual (false, bpg.IsImported, "A4");
298                         Assert.IsTrue (project.IsDirty, "A5");
299                 }
300
301                 [Test]
302                 public void TestBuild0 ()
303                 {
304                         Engine engine;
305                         Project project;
306                         IDictionary hashtable = new Hashtable ();
307
308                         string documentString = @"
309                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
310                                         <Target 
311                                                 Name='Main'
312                                                 Inputs='a;b;c'
313                                                 Outputs='d;e;f'
314                                         >
315                                         </Target>
316                                 </Project>
317                         ";
318
319                         engine = new Engine (Consts.BinPath);
320                         project = engine.CreateNewProject ();
321                         project.LoadXml (documentString);
322
323                         Assert.AreEqual (true, project.Build (new string [] { "Main" }, hashtable), "A1");
324                         Assert.AreEqual (1, hashtable.Count, "A2");
325
326                         IDictionaryEnumerator e = hashtable.GetEnumerator ();
327                         e.MoveNext ();
328
329                         string name = (string) e.Key;
330                         Assert.AreEqual ("Main", name, "A3");
331                         ITaskItem [] arr = (ITaskItem []) e.Value;
332
333                         Assert.AreEqual (3, arr.Length, "A4");
334                         Assert.AreEqual ("d", arr [0].ItemSpec, "A5");
335                         Assert.AreEqual ("e", arr [1].ItemSpec, "A6");
336                         Assert.AreEqual ("f", arr [2].ItemSpec, "A7");
337                 }
338
339                 [Test]
340                 public void TestBuild1 ()
341                 {
342                         Engine engine;
343                         Project project;
344                         IDictionary hashtable = new Hashtable ();
345                         
346                         string documentString = @"
347                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
348                                         <Target Name='Main'>
349                                                 <Microsoft.Build.Tasks.Message Text='Text' />
350                                         </Target>
351                                 </Project>
352                         ";
353                         
354                         engine = new Engine (Consts.BinPath);
355                         project = engine.CreateNewProject ();
356                         project.LoadXml (documentString);
357
358                         Assert.AreEqual (true, project.Build (new string[] { "Main" }, hashtable), "A1");
359                         Assert.AreEqual (1, hashtable.Count, "A2");
360
361                         IDictionaryEnumerator e = hashtable.GetEnumerator ();
362                         e.MoveNext ();
363
364                         string name = (string) e.Key;
365                         Assert.AreEqual ("Main", name, "A3");
366                         Assert.IsNotNull ((ITaskItem []) e.Value, "A4");
367                 }
368
369                 [Test]
370                 public void TestBuild2 ()
371                 {
372                         Engine engine;
373                         Project project;
374
375                         string documentString = @"
376                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
377                                         <Target Name='T'>
378                                                 <Message Text='text' />
379                                         </Target>
380                                 </Project>
381                         ";
382
383                         engine = new Engine (Consts.BinPath);
384                         MBT.TestMessageLogger tl = new MBT.TestMessageLogger();
385                         engine.RegisterLogger (tl);
386                         project = engine.CreateNewProject ();
387                         project.LoadXml (documentString);
388
389                         project.Build ("T");
390                         project.Build ("T");
391
392                         Assert.AreEqual (2, tl.TargetStarted, "A1");
393                         Assert.AreEqual (2, tl.TargetFinished, "A2");
394                         Assert.AreEqual (2, tl.TaskStarted, "A3");
395                         Assert.AreEqual (2, tl.TaskFinished, "A4");
396                 }
397
398                 [Test]
399                 public void TestBuild3 ()
400                 {
401                         Engine engine;
402                         Project project;
403
404                         string documentString = @"
405                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
406                                         <Target Name='T'>
407                                                 <Message Text='text' />
408                                         </Target>
409                                 </Project>
410                         ";
411
412                         engine = new Engine (Consts.BinPath);
413                         MBT.TestMessageLogger tl = new MBT.TestMessageLogger ();
414                         engine.RegisterLogger (tl);
415                         project = engine.CreateNewProject ();
416                         project.LoadXml (documentString);
417
418                         project.Build (new string [1] { "T" }, null, BuildSettings.None);
419                         project.Build (new string [1] { "T" }, null, BuildSettings.None);
420
421                         Assert.AreEqual (2, tl.TargetStarted, "A1");
422                         Assert.AreEqual (2, tl.TargetFinished, "A2");
423                         Assert.AreEqual (2, tl.TaskStarted, "A3");
424                         Assert.AreEqual (2, tl.TaskFinished, "A4");
425                 }
426
427                 [Test]
428                 public void TestBuild4 ()
429                 {
430                         Engine engine;
431                         Project project;
432
433                         string documentString = @"
434                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
435                                         <Target Name='T'>
436                                                 <Message Text='text' />
437                                         </Target>
438                                 </Project>
439                         ";
440
441                         engine = new Engine (Consts.BinPath);
442                         MBT.TestMessageLogger tl = new MBT.TestMessageLogger ();
443                         engine.RegisterLogger (tl);
444                         project = engine.CreateNewProject ();
445                         project.LoadXml (documentString);
446
447                         project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
448                         project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
449
450                         Assert.AreEqual (1, tl.TargetStarted, "A1");
451                         Assert.AreEqual (1, tl.TargetFinished, "A2");
452                         Assert.AreEqual (1, tl.TaskStarted, "A3");
453                         Assert.AreEqual (1, tl.TaskFinished, "A4");
454                 }
455
456                 [Test]
457                 public void TestBuild5 ()
458                 {
459                         Engine engine;
460                         Project project;
461
462                         string documentString = @"
463                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
464                                 </Project>
465                         ";
466
467                         engine = new Engine (Consts.BinPath);
468                         project = engine.CreateNewProject ();
469                         project.LoadXml (documentString);
470
471                         Assert.IsFalse (project.Build ("target_that_doesnt_exist"));
472                 }
473
474                 [Test]
475                 public void TestEvaluatedItems1 ()
476                 {
477                         Engine engine;
478                         Project project;
479
480                         string documentString = @"
481                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
482                                         <ItemGroup>
483                                                 <A Include='a' />
484                                                 <B Include='b' Condition='false' />
485                                         </ItemGroup>
486                                 </Project>
487                         ";
488
489                         engine = new Engine (Consts.BinPath);
490                         project = engine.CreateNewProject ();
491                         project.LoadXml (documentString);
492
493                         Assert.AreEqual (1, project.EvaluatedItems.Count, "A1");
494
495                         BuildItem bi = project.EvaluatedItems [0];
496
497                         bi.Name = "C";
498                         bi.Include = "c";
499
500                         BuildItemGroup [] big = new BuildItemGroup [1];
501                         project.ItemGroups.CopyTo (big, 0);
502                         Assert.AreEqual ("C", big [0] [0].Name, "A2");
503                         Assert.AreEqual ("c", big [0] [0].Include, "A3");
504                 }
505
506                 [Test]
507                 public void TestEvaluatedItems2 ()
508                 {
509                         Engine engine;
510                         Project project;
511
512                         string documentString = @"
513                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
514                                         <ItemGroup>
515                                                 <A Include='a;b;c' />
516                                         </ItemGroup>
517                                 </Project>
518                         ";
519
520                         engine = new Engine (Consts.BinPath);
521                         project = engine.CreateNewProject ();
522                         project.LoadXml (documentString);
523
524                         BuildItemGroup [] big = new BuildItemGroup [1];
525                         project.ItemGroups.CopyTo (big, 0);
526
527                         Assert.AreEqual (3, project.EvaluatedItems.Count, "A1");
528                         Assert.AreEqual ("a;b;c", big [0] [0].Include, "A2");
529                         Assert.AreEqual (1, big [0].Count, "A3");
530
531                         BuildItem bi = project.EvaluatedItems [0];
532
533                         bi.Include = "d";
534
535                         Assert.AreEqual (3, big [0].Count, "A4");
536                         Assert.AreEqual ("d", big [0] [0].Include, "A5");
537                         Assert.AreEqual ("b", big [0] [1].Include, "A6");
538                         Assert.AreEqual ("c", big [0] [2].Include, "A7");
539                 }
540
541                 [Test]
542                 [Category ("NotWorking")]
543                 public void TestGetConditionedPropertyValues ()
544                 {
545                         Engine engine;
546                         Project project;
547
548                         string documentString = @"
549                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
550                                         <PropertyGroup Condition='true'>
551                                                 <A>A</A>
552                                                 <B Condition='true'>A</B>
553                                         </PropertyGroup>
554                                         <PropertyGroup>
555                                                 <C Condition='true'>A</C>
556                                                 <C Condition='false'>B</C>
557                                                 <C Condition='!false'>C</C>
558                                                 <D>A</D>
559                                                 <E Condition="" '$(C)' == 'A' "">E</E>
560                                         </PropertyGroup>
561                                 </Project>
562                         ";
563
564                         engine = new Engine (Consts.BinPath);
565                         project = engine.CreateNewProject ();
566                         project.LoadXml (documentString);
567
568                         Assert.AreEqual (0, project.GetConditionedPropertyValues ("A").Length, "A1");
569                         Assert.AreEqual (0, project.GetConditionedPropertyValues ("B").Length, "A2");
570                         Assert.AreEqual (1, project.GetConditionedPropertyValues ("C").Length, "A3");
571                         Assert.AreEqual (0, project.GetConditionedPropertyValues ("D").Length, "A4");
572                         Assert.AreEqual (0, project.GetConditionedPropertyValues ("E").Length, "A5");
573                         Assert.AreEqual ("A", project.GetConditionedPropertyValues ("C") [0], "A6");
574                 }
575
576                 [Test]
577                 [ExpectedException (typeof (ArgumentNullException))]
578                 public void TestGetEvaluatedItemsByName1 ()
579                 {
580                         Engine engine;
581                         Project project;
582
583                         string documentString = @"
584                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
585                                 </Project>
586                         ";
587
588                         engine = new Engine (Consts.BinPath);
589                         project = engine.CreateNewProject ();
590                         project.LoadXml (documentString);
591
592                         project.GetEvaluatedItemsByName (null);
593                 }
594
595                 [Test]
596                 public void TestGetEvaluatedItemsByName2 ()
597                 {
598                         Engine engine;
599                         Project project;
600
601                         string documentString = @"
602                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
603                                         <ItemGroup>
604                                                 <A Include='1' />
605                                                 <B Include='2' Condition='true' />
606                                                 <C Include='3' Condition='false' />
607                                         </ItemGroup>
608                                 </Project>
609                         ";
610
611                         engine = new Engine (Consts.BinPath);
612                         project = engine.CreateNewProject ();
613                         project.LoadXml (documentString);
614
615                         BuildItemGroup big;
616
617                         big = project.GetEvaluatedItemsByName (String.Empty);
618
619                         Assert.AreEqual (0, big.Count, "A1");
620
621                         big = project.GetEvaluatedItemsByName ("A");
622
623                         Assert.AreEqual (1, big.Count, "A2");
624                         Assert.AreEqual ("1", big [0].FinalItemSpec, "A3");
625
626                         big = project.GetEvaluatedItemsByName ("B");
627
628                         Assert.AreEqual (1, big.Count, "A4");
629                         Assert.AreEqual ("2", big [0].FinalItemSpec, "A5");
630
631                         big = project.GetEvaluatedItemsByName ("C");
632
633                         Assert.AreEqual (0, big.Count, "A6");
634                 }
635
636                 [Test]
637                 [ExpectedException (typeof (ArgumentNullException))]
638                 public void TestGetEvaluatedItemsByNameIgnoringCondition1 ()
639                 {
640                         Engine engine;
641                         Project project;
642
643                         string documentString = @"
644                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
645                                 </Project>
646                         ";
647
648                         engine = new Engine (Consts.BinPath);
649                         project = engine.CreateNewProject ();
650                         project.LoadXml (documentString);
651
652                         project.GetEvaluatedItemsByNameIgnoringCondition (null);
653                 }
654
655                 [Test]
656                 public void TestGetEvaluatedItemsByNameIgnoringCondition2 ()
657                 {
658                         Engine engine;
659                         Project project;
660
661                         string documentString = @"
662                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
663                                         <ItemGroup>
664                                                 <A Include='1' />
665                                                 <B Include='2' Condition='true' />
666                                                 <C Include='3' Condition='false' />
667                                         </ItemGroup>
668                                 </Project>
669                         ";
670
671                         engine = new Engine (Consts.BinPath);
672                         project = engine.CreateNewProject ();
673                         project.LoadXml (documentString);
674
675                         BuildItemGroup big;
676
677                         big = project.GetEvaluatedItemsByNameIgnoringCondition (String.Empty);
678
679                         Assert.AreEqual (0, big.Count, "A1");
680
681                         big = project.GetEvaluatedItemsByNameIgnoringCondition ("A");
682
683                         Assert.AreEqual (1, big.Count, "A2");
684                         Assert.AreEqual ("1", big [0].FinalItemSpec, "A3");
685
686                         big = project.GetEvaluatedItemsByNameIgnoringCondition ("B");
687
688                         Assert.AreEqual (1, big.Count, "A4");
689                         Assert.AreEqual ("2", big [0].FinalItemSpec, "A5");
690
691                         big = project.GetEvaluatedItemsByNameIgnoringCondition ("C");
692
693                         Assert.AreEqual (1, big.Count, "A6");
694                         Assert.AreEqual ("3", big [0].FinalItemSpec, "A7");
695                 }
696
697                 [Test]
698                 [ExpectedException (typeof (ArgumentNullException))]
699                 public void TestGetEvaluatedProperty1 ()
700                 {
701                         Engine engine;
702                         Project project;
703
704                         string documentString = @"
705                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
706                                 </Project>
707                         ";
708
709                         engine = new Engine (Consts.BinPath);
710                         project = engine.CreateNewProject ();
711                         project.LoadXml (documentString);
712
713                         project.GetEvaluatedProperty (null);
714                 }
715                 [Test]
716                 public void TestGetEvaluatedProperty2 ()
717                 {
718                         Engine engine;
719                         Project project;
720
721                         string documentString = @"
722                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
723                                         <PropertyGroup>
724                                                 <A>1</A>
725                                                 <B Condition='true'>2</B>
726                                                 <C Condition='false'>3</C>
727                                         </PropertyGroup>
728                                 </Project>
729                         ";
730
731                         engine = new Engine (Consts.BinPath);
732                         project = engine.CreateNewProject ();
733                         project.LoadXml (documentString);
734
735                         Assert.AreEqual ("1", project.GetEvaluatedProperty ("A"), "A1");
736                         Assert.AreEqual ("2", project.GetEvaluatedProperty ("B"), "A2");
737                         Assert.IsNull (project.GetEvaluatedProperty ("C"), "A3");
738                 }
739
740                 [Test]
741                 public void TestGetProjectExtensions ()
742                 {
743                         Engine engine;
744                         Project project;
745
746                         string documentString = @"
747                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
748                                         <ProjectExtensions>
749                                                 <Node>Text</Node>
750                                         </ProjectExtensions>
751                                 </Project>
752                         ";
753
754                         engine = new Engine (Consts.BinPath);
755                         project = engine.CreateNewProject ();
756                         project.LoadXml (documentString);
757
758                         Assert.AreEqual (String.Empty, project.GetProjectExtensions (null), "A1");
759                         Assert.AreEqual (String.Empty, project.GetProjectExtensions (String.Empty), "A2");
760                         Assert.AreEqual (String.Empty, project.GetProjectExtensions ("something"), "A3");
761                         Assert.AreEqual ("Text", project.GetProjectExtensions ("Node"), "A4");
762                 }
763
764                 [Test]
765                 public void TestGlobalProperties1 ()
766                 {
767                         Engine engine;
768                         Project project;
769                         
770                         string documentString = @"
771                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
772                                 </Project>
773                         ";
774                         
775                         engine = new Engine (Consts.BinPath);
776                         project = engine.CreateNewProject ();
777                         project.LoadXml (documentString);
778
779                         Assert.AreEqual (0, project.GlobalProperties.Count, "A1");
780                 }
781
782                 [Test]
783                 public void TestGlobalProperties2 ()
784                 {
785                         Engine engine;
786                         Project project;
787                         
788                         string documentString = @"
789                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
790                                 </Project>
791                         ";
792                         
793                         engine = new Engine (Consts.BinPath);
794                         engine.GlobalProperties.SetProperty ("Property", "Value");
795                         
796                         project = engine.CreateNewProject ();
797                         project.LoadXml (documentString);
798
799                         Assert.AreEqual (1, project.GlobalProperties.Count, "A1");
800                         Assert.AreEqual ("Property", project.GlobalProperties ["Property"].Name, "A2");
801                         Assert.AreEqual ("Value", project.GlobalProperties ["Property"].Value, "A3");
802                         Assert.AreEqual ("Value", project.GlobalProperties ["Property"].FinalValue, "A4");
803                         Assert.AreEqual ("Property", project.EvaluatedProperties ["Property"].Name, "A2");
804                         Assert.AreEqual ("Value", project.EvaluatedProperties ["Property"].Value, "A3");
805                         Assert.AreEqual ("Value", project.EvaluatedProperties ["Property"].FinalValue, "A4");
806                 }
807
808                 [Test]
809                 [Category ("NotDotNet")]
810                 [ExpectedException (typeof (ArgumentNullException))]
811                 public void TestGlobalProperties3 ()
812                 {
813                         Engine engine;
814                         Project project;
815                         
816                         string documentString = @"
817                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
818                                 </Project>
819                         ";
820                         
821                         engine = new Engine (Consts.BinPath);
822                         project = engine.CreateNewProject ();
823                         project.LoadXml (documentString);
824
825                         project.GlobalProperties = null;
826                 }
827
828                 [Test]
829                 [Ignore ("needs rewriting")]
830                 public void TestGlobalProperties4 ()
831                 {
832                         Engine engine;
833                         Project project;
834                         
835                         string documentString = @"
836                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
837                                         <PropertyGroup>
838                                                 <Property>a</Property>
839                                         </PropertyGroup>
840                                 </Project>
841                         ";
842                         
843                         engine = new Engine (Consts.BinPath);
844                         project = engine.CreateNewProject ();
845                         project.LoadXml (documentString);
846
847                         BuildPropertyGroup[] groups = new BuildPropertyGroup [1];
848                         project.PropertyGroups.CopyTo (groups, 0);
849
850                         project.GlobalProperties = groups [0];
851                         project.GlobalProperties = project.EvaluatedProperties;
852                 }
853
854                 [Test]
855                 [Category ("NotDotNet")]
856                 [ExpectedException (typeof (InvalidOperationException))]
857                 public void TestGlobalProperties5 ()
858                 {
859                         Engine engine;
860                         Project project;
861                         
862                         string documentString = @"
863                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
864                                         <PropertyGroup>
865                                                 <Property>a</Property>
866                                         </PropertyGroup>
867                                 </Project>
868                         ";
869                         
870                         engine = new Engine (Consts.BinPath);
871                         project = engine.CreateNewProject ();
872                         project.LoadXml (documentString);
873
874                         BuildPropertyGroup[] groups = new BuildPropertyGroup [1];
875                         project.PropertyGroups.CopyTo (groups, 0);
876                         project.GlobalProperties = groups [0];
877                 }
878
879                 [Test]
880                 [ExpectedException (typeof (InvalidProjectFileException))]
881                 public void TestLoad1 ()
882                 {
883                         Engine engine;
884                         Project project;
885
886                         string documentString = @"
887                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
888                                         <PropertyGroup>
889                                 </Project>
890                         ";
891
892                         engine = new Engine (Consts.BinPath);
893                         project = engine.CreateNewProject ();
894                         project.LoadXml (documentString);
895                 }
896
897                 [Test]
898                 [ExpectedException (typeof (InvalidProjectFileException))]
899                 public void TestLoad2 ()
900                 {
901                         Engine engine;
902                         Project project;
903
904                         engine = new Engine (Consts.BinPath);
905                         project = engine.CreateNewProject ();
906                         project.LoadXml ("project_file_that_doesnt_exist");
907                 }
908
909                 [Test]
910                 public void TestParentEngine ()
911                 {
912                         Engine engine;
913                         Project project;
914                         
915                         engine = new Engine (Consts.BinPath);
916                         project = engine.CreateNewProject ();
917
918                         Assert.AreEqual (engine, project.ParentEngine, "A1");
919                 }
920
921                 [Test]
922                 [Category ("NotDotNet")]
923                 [ExpectedException (typeof (ArgumentNullException))]
924                 public void TestRemoveItemGroup1 ()
925                 {
926                         Engine engine;
927                         Project p1;
928
929                         engine = new Engine (Consts.BinPath);
930                         p1 = engine.CreateNewProject ();
931
932                         p1.RemoveItemGroup (null);
933                 }
934
935                 // The "BuildItemGroup" object specified does not belong to the correct "Project" object.
936                 [Test]
937                 [ExpectedException (typeof (InvalidOperationException))]
938                 [Category ("NotWorking")]
939                 public void TestRemoveItemGroup2 ()
940                 {
941                         Engine engine;
942                         Project p1;
943                         Project p2;
944                         BuildItemGroup [] groups  = new BuildItemGroup [1];
945
946                         engine = new Engine (Consts.BinPath);
947                         p1 = engine.CreateNewProject ();
948                         p2 = engine.CreateNewProject ();
949
950                         p1.AddNewItem ("A", "B");
951                         p1.ItemGroups.CopyTo (groups, 0);
952
953                         p2.RemoveItemGroup (groups [0]);
954                 }
955
956                 [Test]
957                 [Category ("NotDotNet")]
958                 [ExpectedException (typeof (ArgumentNullException))]
959                 public void TestRemoveItem1 ()
960                 {
961                         Engine engine;
962                         Project project;
963
964                         engine = new Engine (Consts.BinPath);
965                         project = engine.CreateNewProject ();
966
967                         project.RemoveItem (null);
968                 }
969
970                 // The object passed in is not part of the project.
971                 [Test]
972                 [ExpectedException (typeof (InvalidOperationException))]
973                 public void TestRemoveItem2 ()
974                 {
975                         Engine engine;
976                         Project project;
977
978                         engine = new Engine (Consts.BinPath);
979                         project = engine.CreateNewProject ();
980
981                         project.RemoveItem (new BuildItem ("name", "include"));
982                 }
983
984                 // The "BuildItemGroup" object specified does not belong to the correct "Project" object.
985                 [Test]
986                 [ExpectedException (typeof (InvalidOperationException))]
987                 public void TestRemoveItem3 ()
988                 {
989                         Engine engine;
990                         Project p1;
991                         Project p2;
992
993                         engine = new Engine (Consts.BinPath);
994                         p1 = engine.CreateNewProject ();
995                         p2 = engine.CreateNewProject ();
996
997                         p1.AddNewItem ("A", "B");
998
999                         p2.RemoveItem (p1.EvaluatedItems [0]);
1000                 }
1001
1002                 [Test]
1003                 [Category ("NotDotNet")]
1004                 [ExpectedException (typeof (InvalidOperationException))]
1005                 public void TestRemoveItem4 ()
1006                 {
1007                         Engine engine;
1008                         Project p1;
1009                         Project p2;
1010
1011                         engine = new Engine (Consts.BinPath);
1012                         p1 = engine.CreateNewProject ();
1013                         p2 = engine.CreateNewProject ();
1014
1015                         p1.AddNewItem ("A", "B");
1016                         p1.AddNewItem ("A", "C");
1017
1018                         p2.RemoveItem (p1.EvaluatedItems [0]);
1019                 }
1020
1021                 [Test]
1022                 public void TestRemoveItem5 ()
1023                 {
1024                         Engine engine;
1025                         Project project;
1026                         BuildItemGroup [] groups = new BuildItemGroup [1];
1027
1028                         string documentString = @"
1029                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1030                                         <ItemGroup>
1031                                                 <A Include='a'/>
1032                                         </ItemGroup>
1033                                 </Project>
1034                         ";
1035
1036                         engine = new Engine (Consts.BinPath);
1037                         project = engine.CreateNewProject ();
1038                         project.LoadXml (documentString);
1039
1040                         project.RemoveItem (project.EvaluatedItems [0]);
1041                         Assert.AreEqual (0, project.EvaluatedItems.Count, "A1");
1042                         project.ItemGroups.CopyTo (groups, 0);
1043                         Assert.IsNull (groups [0], "A2");
1044                         Assert.AreEqual (0, project.ItemGroups.Count, "A3");
1045                 }
1046
1047                 [Test]
1048                 public void TestResetBuildStatus ()
1049                 {
1050                         Engine engine;
1051                         Project project;
1052
1053                         string documentString = @"
1054                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1055                                         <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'>
1056                                                 <Message Text='text' />
1057                                         </Target>
1058                                 </Project>
1059                         ";
1060
1061                         engine = new Engine (Consts.BinPath);
1062                         TestLogger tl = new TestLogger ();
1063                         engine.RegisterLogger (tl);
1064                         project = engine.CreateNewProject ();
1065                         project.LoadXml (documentString);
1066
1067                         project.Build ("T");
1068                         project.ResetBuildStatus ();
1069                         project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
1070                         project.ResetBuildStatus ();
1071                         project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
1072
1073                         Assert.AreEqual (3, tl.TargetStartedEvents, "A1");
1074                         Assert.AreEqual (3, tl.TargetFinishedEvents, "A1");
1075                 }
1076                 
1077                 [Test]
1078                 public void TestSchemaFile ()
1079                 {
1080                         Engine engine;
1081                         Project project;
1082                         
1083                         string documentString = @"
1084                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1085                                 </Project>
1086                         ";
1087                         
1088                         engine = new Engine (Consts.BinPath);
1089                         project = engine.CreateNewProject ();
1090                         project.LoadXml (documentString);
1091
1092                         Assert.IsNull (project.SchemaFile, "A1");
1093                 }
1094                 [Test]
1095                 [Category ("NotDotNet")]
1096                 [ExpectedException (typeof (ArgumentNullException))]
1097                 public void TestSetProjectExtensions1 ()
1098                 {
1099                         Engine engine;
1100                         Project project;
1101
1102                         string documentString = @"
1103                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1104                                 </Project>
1105                         ";
1106
1107                         engine = new Engine (Consts.BinPath);
1108                         project = engine.CreateNewProject ();
1109                         project.LoadXml (documentString);
1110
1111                         project.SetProjectExtensions (null, null);
1112                 }
1113
1114                 [Test]
1115                 public void TestSetProjectExtensions2 ()
1116                 {
1117                         Engine engine;
1118                         Project project;
1119
1120                         string documentString = @"
1121                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1122                                 </Project>
1123                         ";
1124
1125                         engine = new Engine (Consts.BinPath);
1126                         project = engine.CreateNewProject ();
1127                         project.LoadXml (documentString);
1128
1129                         project.SetProjectExtensions ("name", "1");
1130                         Assert.AreEqual ("1", project.GetProjectExtensions ("name"), "A1");
1131                         project.SetProjectExtensions ("name", "2");
1132                         Assert.AreEqual ("2", project.GetProjectExtensions ("name"), "A2");
1133                         Assert.IsTrue (project.IsDirty, "A3");
1134                 }
1135
1136                 [Test]
1137                 public void TestSetProjectExtensions3 ()
1138                 {
1139                         Engine engine;
1140                         Project project;
1141
1142                         string documentString = @"
1143                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1144                                         <ProjectExtensions>
1145                                         </ProjectExtensions>
1146                                 </Project>
1147                         ";
1148
1149                         engine = new Engine (Consts.BinPath);
1150                         project = engine.CreateNewProject ();
1151                         project.LoadXml (documentString);
1152
1153                         project.SetProjectExtensions ("name", "1");
1154                         Assert.AreEqual ("1", project.GetProjectExtensions ("name"), "A1");
1155                         Assert.IsTrue (project.IsDirty, "A2");
1156                 }
1157
1158                 [Test]
1159                 public void TestBuildProjectError1 ()
1160                 {
1161                         Engine engine = new Engine (Consts.BinPath);
1162                         Project project = engine.CreateNewProject ();
1163
1164                         Assert.IsFalse (project.Build ((string) null), "A1");
1165                         Assert.IsFalse (project.Build ((string[]) null), "A2");
1166                         Assert.IsFalse (project.Build ((string []) null, null), "A3");
1167                         Assert.IsFalse (project.Build ((string []) null, null, BuildSettings.None), "A4");
1168                 }
1169
1170                 [Test]
1171                 public void TestBuildProjectError2 ()
1172                 {
1173                         Engine engine = new Engine (Consts.BinPath);
1174                         Project project = engine.CreateNewProject ();
1175
1176                         try {
1177                                 project.Build (new string [] { null });
1178                         } catch {
1179                                 return;
1180                         }
1181                         Assert.Fail ("Expected exception for project.Build, null string in targetNames []");
1182                 }
1183
1184                 [Test]
1185                 public void TestBuildProjectFile1 ()
1186                 {
1187                         Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2" }, new bool [] { true, true }, "TBPF1");
1188                         CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPF1");
1189                 }
1190
1191                 [Test]
1192                 public void TestBuildProjectFileXml1 ()
1193                 {
1194                         Project project = CreateAndLoadProject (null, false, new string [] { "1", "2" }, new bool [] { true, true }, "TBPFX1");
1195                         CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPFX1");
1196                 }
1197
1198                 [Test]
1199                 public void TestBuildProjectFile2 ()
1200                 {
1201                         Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPF2");
1202                         CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPF2");
1203                 }
1204
1205                 [Test]
1206                 public void TestBuildProjectFileXml2 ()
1207                 {
1208                         Project project = CreateAndLoadProject (null, false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPFX2");
1209                         CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPFX2");
1210                 }
1211
1212                 [Test]
1213                 public void TestBuildProjectFile3 ()
1214                 {
1215                         Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPF3");
1216                         CheckProjectBuild (project, new string [] { "1", "2" }, true, new string [] { "1", "2" }, "TBPF3");
1217                 }
1218
1219                 [Test]
1220                 public void TestBuildProjectFileXml3 ()
1221                 {
1222                         Project project = CreateAndLoadProject (null, false, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPFX3");
1223                         CheckProjectBuild (project, new string [] { "1", "2" }, true, new string [] { "1", "2" }, "TBPFX3");
1224                 }
1225
1226                 [Test]
1227                 public void TestBuildProjectFile4 ()
1228                 {
1229                         Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPF4");
1230                         CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPF4");
1231                 }
1232
1233                 [Test]
1234                 public void TestBuildProjectFileXml4 ()
1235                 {
1236                         Project project = CreateAndLoadProject (null, false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPFX4");
1237                         CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPFX4");
1238                 }
1239
1240                 //Run separate tests
1241
1242                 //Run single target
1243                 [Test]
1244                 public void TestBuildProjectFile5 ()
1245                 {
1246                         Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPF5");
1247                         CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPF5");
1248                 }
1249
1250                 [Test]
1251                 public void TestBuildProjectFileXml5 ()
1252                 {
1253                         Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPFX5");
1254                         CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPFX5");
1255                 }
1256
1257                 [Test]
1258                 public void TestBuildProjectFile6 ()
1259                 {
1260                         Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPF6");
1261                         CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPF6");
1262                 }
1263
1264                 [Test]
1265                 public void TestBuildProjectFileXml6 ()
1266                 {
1267                         Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPFX6");
1268                         CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPFX6");
1269                 }
1270
1271                 // run multiple targets
1272                 [Test]
1273                 public void TestBuildProjectFile7 ()
1274                 {
1275                         Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPF7");
1276                         CheckProjectBuild (project, new string [] { "1", "2", "3" }, true, new string [] { "1", "2", "3" }, "TBPF7");
1277                 }
1278
1279                 [Test]
1280                 public void TestBuildProjectFileXml7 ()
1281                 {
1282                         Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPFX7");
1283                         CheckProjectBuild (project, new string [] { "1", "2", "3" }, true, new string [] { "1", "2", "3" }, "TBPFX7");
1284                 }
1285
1286                 [Test]
1287                 public void TestBuildProjectFile8 ()
1288                 {
1289                         Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, true, false }, "TBPF8");
1290                         CheckProjectBuild (project, new string [] { "1", "2", "3" }, false, new string [] { "1", "2"}, "TBPF8");
1291                 }
1292
1293                 [Test]
1294                 public void TestBuildProjectFileXml8 ()
1295                 {
1296                         Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, true, false }, "TBPFX8");
1297                         CheckProjectBuild (project, new string [] { "1", "2", "3" }, false, new string [] { "1", "2"}, "TBPFX8");
1298                 }
1299
1300                 [Test]
1301                 public void TestBatchedMetadataRef1 ()
1302                 {
1303                         //test for multiple items with same metadata also
1304                          string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1305                         <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1306                         <ItemGroup>
1307                                 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1308                                 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1309                                 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1310                                 <Coll1 Include=""A4""><Name>Xyz</Name></Coll1>
1311                                 <Coll2 Include=""B1""></Coll2>
1312                         </ItemGroup>
1313                                 <Target Name=""ShowMessage"">
1314                                         <BatchingTestTask Sources=""%(Coll1.Name)"">
1315                                                 <Output TaskParameter=""Output"" ItemName=""FinalList"" />
1316                                         </BatchingTestTask>
1317                                         <Message Text=""Msg: %(Coll1.Name)"" />
1318                                 </Target>
1319                  </Project>";
1320
1321                         Engine engine = new Engine (Consts.BinPath);
1322                         Project project = engine.CreateNewProject ();
1323
1324                         project.LoadXml (projectString);
1325                         Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
1326
1327                         BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1328                         Assert.AreEqual (3, include.Count, "A2");
1329
1330                         Assert.AreEqual ("FinalList", include [0].Name, "A3");
1331                         Assert.AreEqual ("Abc", include [0].FinalItemSpec, "A4");
1332
1333                         Assert.AreEqual ("FinalList", include [1].Name, "A5");
1334                         Assert.AreEqual ("Def", include [1].FinalItemSpec, "A6");
1335
1336                         Assert.AreEqual ("FinalList", include [2].Name, "A7");
1337                         Assert.AreEqual ("Xyz", include [2].FinalItemSpec, "A8");
1338                 }
1339
1340                 [Test]
1341                 public void TestBatchedMetadataRef2 ()
1342                 {
1343                         string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1344                         <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1345                         <ItemGroup>
1346                                 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1347                                 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1348                                 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1349                                 <Coll1 Include=""A4""><Name>Abc</Name></Coll1>
1350                                 <Coll2 Include=""B1""><Name>Bar</Name></Coll2>
1351                                 <Coll2 Include=""B2""><Name>Bar</Name></Coll2>
1352                         </ItemGroup>
1353                                 <Target Name=""ShowMessage"">
1354                                         <BatchingTestTask Sources=""%(Name)"" Strings=""@(Coll2)"">
1355                                                 <Output TaskParameter=""Output"" ItemName=""FinalList"" />
1356                                         </BatchingTestTask>
1357                                         <Message Text=""Msg: %(Coll1.Name)"" />
1358                                 </Target>
1359                                 <Target Name=""ShowMessage2"">
1360                                         <BatchingTestTask Sources=""%(Name)"" Strings=""@(Coll1)"">
1361                                                 <Output TaskParameter=""Output"" ItemName=""FinalList2"" />
1362                                         </BatchingTestTask>
1363                                         <Message Text=""Msg: %(Coll1.Name)"" />
1364                                 </Target>
1365                  </Project>";
1366
1367                         Engine engine = new Engine (Consts.BinPath);
1368                         Project project = engine.CreateNewProject ();
1369
1370                         project.LoadXml (projectString);
1371                         Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
1372
1373                         BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1374                         Assert.AreEqual (1, include.Count, "A2");
1375
1376                         Assert.AreEqual ("FinalList", include [0].Name, "A3");
1377                         Assert.AreEqual ("Bar", include [0].FinalItemSpec, "A4");
1378
1379                         Assert.IsTrue (project.Build ("ShowMessage2"), "A1: Build failed");
1380                         include = project.GetEvaluatedItemsByName ("FinalList2");
1381                         Assert.AreEqual (3, include.Count, "A5");
1382
1383                         Assert.AreEqual ("FinalList2", include [0].Name, "A6");
1384                         Assert.AreEqual ("Abc", include [0].FinalItemSpec, "A7");
1385
1386                         Assert.AreEqual ("FinalList2", include [1].Name, "A8");
1387                         Assert.AreEqual ("Def", include [1].FinalItemSpec, "A9");
1388
1389                         Assert.AreEqual ("FinalList2", include [2].Name, "A10");
1390                         Assert.AreEqual ("Xyz", include [2].FinalItemSpec, "A11");
1391                 }
1392
1393                 [Test]
1394                 public void TestBatchedMetadataRef3 ()
1395                 {
1396                         string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1397                         <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1398                         <ItemGroup>
1399                                 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1400                                 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1401                                 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1402                                 <Coll1 Include=""A4""><Name>Abc</Name></Coll1>
1403                                 <Coll2 Include=""B1""><Name>Bar</Name></Coll2>
1404                                 <Coll2 Include=""B2""><Name>Bar</Name></Coll2>
1405                         </ItemGroup>
1406                                 <Target Name=""ShowMessage"">
1407                                         <BatchingTestTask SingleTaskItem=""%(Coll2.Name)"" >
1408                                                 <Output TaskParameter=""SingleStringOutput"" ItemName=""FinalList"" />
1409                                         </BatchingTestTask>
1410                                         <Message Text=""Msg: %(Coll1.Name)"" />
1411                                 </Target>
1412                  </Project>";
1413
1414                         Engine engine = new Engine (Consts.BinPath);
1415                         Project project = engine.CreateNewProject ();
1416
1417                         project.LoadXml (projectString);
1418                         Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
1419
1420                         BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1421                         Assert.AreEqual (1, include.Count, "A2");
1422
1423                         Assert.AreEqual ("FinalList", include [0].Name, "A3");
1424                         Assert.AreEqual ("Bar", include [0].FinalItemSpec, "A4");
1425
1426                 }
1427
1428                 [Test]
1429                 public void TestBatchedMetadataRef4 ()
1430                 {
1431                         string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1432                         <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1433                         <ItemGroup>
1434                                 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1435                                 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1436                                 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1437                                 <Coll2 Include=""B1""><Name>Bar</Name></Coll2>
1438                         </ItemGroup>
1439                                 <Target Name=""ShowMessage"">
1440                                         <BatchingTestTask SingleTaskItem=""%(Coll3.Name)"" >
1441                                                 <Output TaskParameter=""SingleStringOutput"" ItemName=""FinalList"" />
1442                                         </BatchingTestTask>
1443                                 </Target>
1444                  </Project>";
1445
1446                         Engine engine = new Engine (Consts.BinPath);
1447                         Project project = engine.CreateNewProject ();
1448
1449                         project.LoadXml (projectString);
1450                         Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
1451
1452                         BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1453                         Assert.AreEqual (0, include.Count, "A2");
1454                 }
1455
1456                 [Test]
1457                 public void TestBatchedMetadataRef5 ()
1458                 {
1459                         string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1460                         <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1461                         <ItemGroup>
1462                                 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1463                                 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1464                                 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1465                                 <Coll2 Include=""B1""><Name>Bar</Name></Coll2>
1466                         </ItemGroup>
1467                                 <Target Name=""ShowMessage"">
1468                                         <Message Text=""Coll1: @(Coll1->'Foo%(Name)Bar')"" />
1469                                         <BatchingTestTask Sources=""@(Coll1->'Foo%(Name)Bar')"" >
1470                                                 <Output TaskParameter=""Output"" ItemName=""FinalList"" />
1471                                         </BatchingTestTask>
1472                                 </Target>
1473                  </Project>";
1474
1475                         Engine engine = new Engine (Consts.BinPath);
1476                         Project project = engine.CreateNewProject ();
1477                         MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
1478                                 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
1479                         engine.RegisterLogger (logger);
1480
1481                         project.LoadXml (projectString);
1482                         bool result = project.Build ("ShowMessage");
1483                         if (!result) {
1484                                 logger.DumpMessages ();
1485                                 Assert.Fail ("A1: Build failed");
1486                         }
1487                         logger.DumpMessages ();
1488                         BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1489                         Assert.AreEqual (3, include.Count, "A2");
1490                 }
1491
1492                 [Test]
1493                 public void TestInitialTargets ()
1494                 {
1495                         Engine engine = new Engine (Consts.BinPath);
1496                         Project project = engine.CreateNewProject ();
1497
1498                         project.LoadXml (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" InitialTargets=""pre  "">
1499                                 <Target Name=""boo"">
1500                                         <Message Text=""Executing boo target""/>
1501                                 </Target>
1502                                 <Target Name=""pre"">
1503                                         <Message Text=""Executing pre target""/>
1504                                 </Target>
1505                         </Project>");
1506
1507                         MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
1508                                 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
1509                         engine.RegisterLogger (logger);
1510
1511                         try {
1512                                 Assert.IsTrue (project.Build (), "Build failed");
1513
1514                                 Assert.AreEqual (0, logger.CheckHead ("Executing pre target", MessageImportance.Normal), "A1");
1515                                 Assert.AreEqual (0, logger.CheckHead ("Executing boo target", MessageImportance.Normal), "A2");
1516                                 Assert.AreEqual (0, logger.Count, "A3");
1517                         } catch {
1518                                 logger.DumpMessages ();
1519                                 throw;
1520                         }
1521                 }
1522
1523                 [Test]
1524                 public void TestRequiredTask_String1 ()
1525                 {
1526                         CheckProjectForRequiredTests ("RequiredTestTask_String", "@(NonExistant)",
1527                                 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_String");
1528                 }
1529
1530                 [Test]
1531                 public void TestRequiredTask_String2 ()
1532                 {
1533                         CheckProjectForRequiredTests ("RequiredTestTask_String", "$(NonExistant)",
1534                                 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_String");
1535                 }
1536
1537                 [Test]
1538                 public void TestRequiredTask_TaskItem1 ()
1539                 {
1540                         Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItem", "@(NonExistant)",
1541                                 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_TaskItem");
1542                 }
1543
1544                 [Test]
1545                 public void TestRequiredTask_TaskItem2 ()
1546                 {
1547                         Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItem", "$(NonExistant)",
1548                                 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_TaskItem");
1549                 }
1550
1551                 [Test]
1552                 public void TestRequiredTask_TaskItemArray1 ()
1553                 {
1554                         Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItems", "@(NonExistant)",
1555                                 true, "Build failed");
1556
1557                         BuildItemGroup group = p.GetEvaluatedItemsByName ("OutItem");
1558                         Assert.AreEqual (1, group.Count, "A2");
1559                         Assert.AreEqual ("count: 0", group [0].FinalItemSpec, "A3");
1560                 }
1561
1562                 [Test]
1563                 public void TestRequiredTask_TaskItemArray2 ()
1564                 {
1565                         Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItems", "$(NonExistant)",
1566                                 true, "Build failed");
1567
1568                         BuildItemGroup group = p.GetEvaluatedItemsByName ("OutItem");
1569                         Assert.AreEqual (1, group.Count, "A2");
1570                         Assert.AreEqual ("count: 0", group [0].FinalItemSpec, "A3");
1571                 }
1572
1573                 [Test]
1574                 public void TestRequiredTask_TaskItemArray3 ()
1575                 {
1576                         Project p = CheckProjectForRequiredTests ("RequiredTestTask_IntArray", "$(NonExistant)",
1577                                 true, "Build failed");
1578
1579                         BuildItemGroup group = p.GetEvaluatedItemsByName ("OutItem");
1580                         Assert.AreEqual (1, group.Count, "A2");
1581                         Assert.AreEqual ("count: 0", group [0].FinalItemSpec, "A3");
1582                 }
1583
1584                 // full solution test
1585                 //[Test]
1586                 public void TestBuildSolutionProject ()
1587                 {
1588                         string basepath = Path.Combine ("Test", Path.Combine ("resources", "Project01"));
1589                         string [] project_dirs = new string [] {
1590                                 Path.Combine (basepath, "Lib4"),
1591                                 Path.Combine (basepath, "Lib3"),
1592                                 Path.Combine (basepath, "Lib2"),
1593                                 Path.Combine (basepath, "Lib1"),
1594                                 Path.Combine (basepath, "Project01")
1595                         };
1596                         string debug_extn = Consts.RunningOnMono () ? ".dll.mdb" : ".pdb";
1597
1598                         // List of expected output files
1599                         // Lib3
1600                         string [] [] project_files = new string [5][] {
1601                                 new string [] { "Lib4.dll", "Lib4" + debug_extn },
1602                                 new string [] { "Lib3.dll" , "Lib3" + debug_extn },
1603                                 // Lib2
1604                                 new string [] {
1605                                         "Lib2.dll", "Lib2" + debug_extn,
1606                                         "lib2_folder/Lib2.deploy.txt",
1607                                         Path.Combine ("fr-CA", "Lib2.resources.dll"),
1608                                         Path.Combine ("fr-FR", "Lib2.resources.dll"),
1609                                         "Lib4.dll", "Lib4" + debug_extn
1610                                 },
1611                                 
1612                                 // lib1
1613                                 new string [] {
1614                                         // lib1 files
1615                                         "Lib1.dll", "Lib2" + debug_extn,
1616                                         "Lib1.deploy.txt",
1617                                         Path.Combine ("fr-CA", "Lib1.resources.dll"),
1618                                         Path.Combine ("fr-FR", "Lib1.resources.dll"),
1619                                         Path.Combine ("en-US", "Lib1.resources.dll"),
1620                                         // lib2 files
1621                                         "Lib2.dll", "Lib2" + debug_extn,
1622                                         "lib2_folder/Lib2.deploy.txt",
1623                                         Path.Combine ("fr-CA", "Lib2.resources.dll"),
1624                                         Path.Combine ("fr-FR", "Lib2.resources.dll"),
1625                                         // lib3 files
1626                                         "Lib3.dll", "Lib3" + debug_extn,
1627                                         "Lib4.dll", "Lib4" + debug_extn
1628                                         },
1629
1630                                 new string [] {
1631                                         "Project01.exe",
1632                                         "Project01" + (Consts.RunningOnMono () ? ".exe.mdb" : ".pdb"),
1633                                         // lib1 files
1634                                         "Lib1.dll", "Lib1" + debug_extn,
1635                                         "Lib1.deploy.txt",
1636                                         Path.Combine ("fr-CA", "Lib1.resources.dll"),
1637                                         Path.Combine ("fr-FR", "Lib1.resources.dll"),
1638                                         Path.Combine ("en-US", "Lib1.resources.dll"),
1639                                         // lib2 files
1640                                         "Lib2.dll", "Lib2" + debug_extn,
1641                                         "lib2_folder/Lib2.deploy.txt",
1642                                         Path.Combine ("fr-CA", "Lib2.resources.dll"),
1643                                         Path.Combine ("fr-FR", "Lib2.resources.dll"),
1644                                         "Lib4.dll", "Lib4" + debug_extn,
1645                                         }
1646                         };
1647
1648                         // Cleanup
1649                         for (int i = 0; i < project_dirs.Length; i ++) {
1650                                 string bin_path = Path.Combine (project_dirs [i], Path.Combine ("bin", "Debug"));
1651                                 string obj_path = Path.Combine (project_dirs [i], Path.Combine ("obj", "Debug"));
1652
1653                                 DeleteAllInDir (bin_path);
1654
1655                                 DeleteAllInDir (obj_path);
1656                         }
1657
1658                         Engine engine = new Engine (Consts.BinPath);
1659                         MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
1660                                 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
1661                         engine.RegisterLogger (logger);
1662
1663                         engine.GlobalProperties = new BuildPropertyGroup ();
1664                         engine.GlobalProperties.SetProperty ("TreatWarningsAsErrors", "false");
1665
1666                         Project project = engine.CreateNewProject ();
1667                         project.Load (Path.Combine (basepath, "Project01.sln.proj"));
1668                         
1669                         bool result = project.Build ();
1670                         if (!result) {
1671                                 logger.DumpMessages ();
1672                                 Assert.Fail ("Build failed");
1673                         }
1674
1675                         // We check only the output dir, not the 'obj'
1676                         string debug = Path.Combine ("bin", "Debug");
1677                         for (int i = 0; i < project_dirs.Length; i++) {
1678                                 CheckFilesExistInDir (Path.Combine (project_dirs [i], debug),
1679                                         project_files [i]);
1680                         }
1681                 }
1682
1683                 void DeleteAllInDir (string path)
1684                 {
1685                         if (!Directory.Exists (path))
1686                                 return;
1687
1688                         foreach (string file in Directory.GetFiles (path))
1689                                 File.Delete (file);
1690                         Directory.Delete (path, true);
1691                 }
1692
1693                 void CheckFilesExistInDir (string dir, params string [] files)
1694                 {
1695                         foreach (string file in files) {
1696                                 string path = Path.Combine (dir, file);
1697                                 Assert.IsTrue (File.Exists (path),
1698                                         String.Format ("Expected to find file {0}", path));
1699                         }
1700                 }
1701
1702                 Project CheckProjectForRequiredTests (string taskname, string property_arg, bool expected_result, string error_msg)
1703                 {
1704                         string projectString = String.Format (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1705                                 <UsingTask TaskName=""{0}"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1706                                 <Target Name=""foo"">
1707                                         <{0} Property=""{1}"">
1708                                                 <Output TaskParameter=""Output"" ItemName=""OutItem""/>
1709                                         </{0}>
1710                                 </Target>
1711                         </Project>", taskname, property_arg);
1712
1713                         Engine engine = new Engine (Consts.BinPath);
1714                         MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
1715                                 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
1716                         engine.RegisterLogger (logger);
1717                         Project project = engine.CreateNewProject ();
1718                         project.LoadXml (projectString);
1719
1720                         try {
1721                                 Assert.AreEqual (expected_result, project.Build (), error_msg);
1722                         } finally {
1723                                 logger.DumpMessages ();
1724                         }
1725                         return project;
1726                 }
1727
1728                 static void CheckBuildItem (BuildItem item, string name, string [,] metadata, string finalItemSpec, string prefix)
1729                 {
1730                         Assert.AreEqual (name, item.Name, prefix + "#1");
1731                         for (int i = 0; i < metadata.GetLength (0); i++) {
1732                                 string key = metadata [i, 0];
1733                                 string val = metadata [i, 1];
1734                                 Assert.IsTrue (item.HasMetadata (key), String.Format ("{0}#2: Expected metadata '{1}' not found", prefix, key));
1735                                 Assert.AreEqual (val, item.GetMetadata (key), String.Format ("{0}#3: Value for metadata {1}", prefix, key));
1736                                 Assert.AreEqual (val, item.GetEvaluatedMetadata (key), String.Format ("{0}#4: Value for evaluated metadata {1}", prefix, key));
1737                         }
1738                         Assert.AreEqual (finalItemSpec, item.FinalItemSpec, prefix + "#5");
1739                 }
1740
1741                 void CheckProjectBuild (Project project, string [] targetNames, bool result, string [] outputNames, string prefix)
1742                 {
1743                         IDictionary targetOutputs = new Hashtable ();
1744
1745                         Assert.AreEqual (result, project.Build (targetNames, targetOutputs), prefix + "A1");
1746                         Assert.AreEqual (outputNames.Length, targetOutputs.Keys.Count, prefix + "A2");
1747
1748                         foreach (string outputName in outputNames) {
1749                                 Assert.IsTrue (targetOutputs.Contains (outputName), prefix + " A3: target " + outputName);
1750
1751                                 object o = targetOutputs [outputName];
1752                                 Assert.IsTrue (typeof (ITaskItem []).IsAssignableFrom (o.GetType ()), prefix + " A4: target " + outputName);
1753
1754                                 ITaskItem [] items = (ITaskItem [])o;
1755                                 Assert.AreEqual (0, items.Length, prefix + "A5: target " + outputName);
1756                         }
1757                 }
1758
1759                 string CreateProjectString (bool run_separate, string [] targets, bool [] results, string prefix)
1760                 {
1761                         StringBuilder sb = new StringBuilder ();
1762                         sb.Append (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">");
1763                         sb.AppendFormat ("<Target Name = \"{0}\"><Message Text = \"#Target {1}:{0} called\" />", "main", prefix);
1764
1765                         sb.AppendFormat ("<CallTarget Targets=\"");
1766                         for (int i = 0; i < targets.Length; i++)
1767                                 sb.AppendFormat ("{0};", targets [i]);
1768                         sb.AppendFormat ("\" ");
1769
1770                         if (run_separate)
1771                                 sb.AppendFormat (" RunEachTargetSeparately=\"true\" ");
1772                         sb.AppendFormat ("/></Target>\n");
1773
1774                         for (int i = 0; i < targets.Length; i++) {
1775                                 sb.AppendFormat ("<Target Name = \"{0}\"><Message Text = \"#Target {1}:{0} called\" />", targets [i], prefix);
1776                                 if (!results [i])
1777                                         sb.AppendFormat ("<Error Text = \"#Error message for target {0}:{1}\"/>", prefix, targets [i]);
1778                                 sb.Append ("</Target>\n");
1779                         }
1780
1781                         sb.Append ("</Project>");
1782
1783                         return sb.ToString ();
1784                 }
1785
1786                 void CreateProjectFile (string fname, bool run_separate, string [] targets, bool [] results, string prefix)
1787                 {
1788                         using (StreamWriter sw = new StreamWriter (fname))
1789                                 sw.Write (CreateProjectString (run_separate, targets, results, prefix));
1790                 }
1791
1792                 Project CreateAndLoadProject (string fname, bool run_separate, string [] targets, bool [] results, string prefix)
1793                 {
1794                         Engine engine = new Engine (Consts.BinPath);
1795                         Project project = engine.CreateNewProject ();
1796
1797                         string projectXml = CreateProjectString (run_separate, targets, results, prefix);
1798                         if (fname == null) {
1799                                 project.LoadXml (projectXml);
1800                         } else {
1801                                 using (StreamWriter sw = new StreamWriter (fname))
1802                                         sw.Write (projectXml);
1803                                 project.Load (fname);
1804                                 File.Delete (fname);
1805                         }
1806
1807                         return project;
1808                 }
1809         }
1810 }