1 // 2 // ProjectTest.cs: 3 // 4 // Author: 5 // Marek Sieradzki (marek.sieradzki@gmail.com) 6 // Ankit Jain (jankit@novell.com) 7 // 8 // (C) 2005 Marek Sieradzki 9 // Copyright 2009 Novell, Inc (http://www.novell.com) 10 // 11 // Permission is hereby granted, free of charge, to any person obtaining 12 // a copy of this software and associated documentation files (the 13 // "Software"), to deal in the Software without restriction, including 14 // without limitation the rights to use, copy, modify, merge, publish, 15 // distribute, sublicense, and/or sell copies of the Software, and to 16 // permit persons to whom the Software is furnished to do so, subject to 17 // the following conditions: 18 // 19 // The above copyright notice and this permission notice shall be 20 // included in all copies or substantial portions of the Software. 21 // 22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 30 using System; 31 using System.Collections; 32 using System.Collections.Generic; 33 using System.IO; 34 using System.Xml; 35 using Microsoft.Build.BuildEngine; 36 using Microsoft.Build.Framework; 37 using Microsoft.Build.Utilities; 38 using NUnit.Framework; 39 using System.Text; 40 41 using MBT = MonoTests.Microsoft.Build.Tasks; 42 43 namespace MonoTests.Microsoft.Build.BuildEngine { 44 45 class TestLogger : Logger { 46 int target_started_events = 0; 47 int target_finished_events = 0; 48 Initialize(IEventSource eventSource)49 public override void Initialize (IEventSource eventSource) 50 { 51 eventSource.TargetStarted += new TargetStartedEventHandler(TargetStarted); 52 eventSource.TargetFinished += new TargetFinishedEventHandler(TargetFinished); 53 eventSource.MessageRaised += new BuildMessageEventHandler(Message); 54 eventSource.WarningRaised += new BuildWarningEventHandler(Warning); 55 } 56 TargetStarted(object sender, TargetStartedEventArgs args)57 void TargetStarted (object sender, TargetStartedEventArgs args) 58 { 59 target_started_events++; 60 } 61 TargetFinished(object sender, TargetFinishedEventArgs args)62 void TargetFinished (object sender, TargetFinishedEventArgs args) 63 { 64 target_finished_events++; 65 } 66 Message(object sender, BuildMessageEventArgs args)67 void Message (object sender, BuildMessageEventArgs args) 68 { 69 } 70 Warning(object sender, BuildWarningEventArgs args)71 void Warning (object sender, BuildWarningEventArgs args) 72 { 73 } 74 75 public int TargetStartedEvents { get { return target_started_events; } } 76 77 public int TargetFinishedEvents { get { return target_finished_events; } } 78 } 79 80 [TestFixture] 81 public class ProjectTest { 82 83 /* 84 Import [] GetImports (ImportCollection ic) 85 { 86 List<Import> list = new List<Import> (); 87 foreach (Import i in ic) 88 list.Add (i); 89 return list.ToArray (); 90 } 91 */ 92 93 [Test] TestAssignment1()94 public void TestAssignment1 () 95 { 96 Engine engine; 97 Project project; 98 string documentString = 99 "<Project></Project>"; 100 101 engine = new Engine (Consts.BinPath); 102 103 DateTime time = DateTime.Now; 104 project = engine.CreateNewProject (); 105 try { 106 project.LoadXml (documentString); 107 } catch (InvalidProjectFileException) { 108 Assert.AreEqual (true, project.BuildEnabled, "A1"); 109 Assert.AreEqual (String.Empty, project.DefaultTargets, "A2"); 110 Assert.AreEqual (String.Empty, project.FullFileName, "A3"); 111 Assert.AreEqual (false, project.IsDirty, "A4"); 112 Assert.AreEqual (false, project.IsValidated, "A5"); 113 Assert.AreEqual (engine, project.ParentEngine, "A6"); 114 //Console.WriteLine ("time: {0} p.t: {1}", time, project.TimeOfLastDirty); 115 Assert.IsTrue (time <= project.TimeOfLastDirty, "A7"); 116 Assert.IsTrue (String.Empty != project.Xml, "A8"); 117 return; 118 } 119 120 Assert.Fail ("Expected InvalidProjectFileException"); 121 } 122 123 [Test] TestAssignment2()124 public void TestAssignment2 () 125 { 126 Engine engine; 127 Project project; 128 string documentString = 129 "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"></Project>"; 130 131 engine = new Engine (Consts.BinPath); 132 DateTime time = DateTime.Now; 133 project = engine.CreateNewProject (); 134 project.LoadXml (documentString); 135 136 Assert.AreEqual (true, project.BuildEnabled, "A1"); 137 Assert.AreEqual (String.Empty, project.DefaultTargets, "A2"); 138 Assert.AreEqual (String.Empty, project.FullFileName, "A3"); 139 Assert.AreEqual (true, project.IsDirty, "A4"); 140 Assert.AreEqual (false, project.IsValidated, "A5"); 141 Assert.AreEqual (engine, project.ParentEngine, "A6"); 142 Assert.IsTrue (time <= project.TimeOfLastDirty, "A7"); 143 Assert.IsTrue (String.Empty != project.Xml, "A8"); 144 } 145 146 [Test] 147 [Category ("NotWorking")] TestAddNewImport1()148 public void TestAddNewImport1 () 149 { 150 Engine engine; 151 Project project; 152 153 string documentString = @" 154 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 155 <PropertyGroup /> 156 <ItemGroup /> 157 <Target Name='a' /> 158 <Import Project='Test/resources/Import.csproj' /> 159 </Project> 160 "; 161 162 engine = new Engine (Consts.BinPath); 163 project = engine.CreateNewProject (); 164 project.LoadXml (documentString); 165 166 project.AddNewImport ("a", "true"); 167 // reevaluation wasn't caused by anything so it has only old import 168 Assert.AreEqual (1, project.Imports.Count, "A1"); 169 } 170 171 [Test] 172 [Ignore ("Too detailed probably (implementation specific)")] TestAddNewItem1()173 public void TestAddNewItem1 () 174 { 175 Engine engine; 176 Project project; 177 BuildItemGroup [] groups = new BuildItemGroup [1]; 178 179 string documentString = @" 180 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 181 </Project> 182 "; 183 184 engine = new Engine (Consts.BinPath); 185 project = engine.CreateNewProject (); 186 project.LoadXml (documentString); 187 188 BuildItem item = project.AddNewItem ("A", "B"); 189 190 Assert.AreEqual (1, project.ItemGroups.Count, "A1"); 191 project.ItemGroups.CopyTo (groups, 0); 192 Assert.AreEqual (1, groups [0].Count, "A2"); 193 Assert.AreEqual ("B", groups [0] [0].Include, "A3"); 194 Assert.AreEqual ("B", groups [0] [0].FinalItemSpec, "A4"); 195 Assert.AreEqual ("A", groups [0] [0].Name, "A5"); 196 //Assert.AreNotSame (item, groups [0] [0], "A6"); 197 Assert.IsFalse (object.ReferenceEquals (item, groups [0] [0]), "A6"); 198 199 Assert.AreEqual (1, project.EvaluatedItems.Count, "A7"); 200 Assert.AreEqual ("B", project.EvaluatedItems [0].Include, "A8"); 201 Assert.AreEqual ("B", project.EvaluatedItems [0].FinalItemSpec, "A9"); 202 Assert.AreEqual ("A", project.EvaluatedItems [0].Name, "A10"); 203 //Assert.AreNotSame (item, project.EvaluatedItems [0], "A11"); 204 Assert.IsFalse (object.ReferenceEquals (item, project.EvaluatedItems [0]), "A11"); 205 } 206 207 [Test] 208 [Category ("NotWorking")] TestAddNewItem2()209 public void TestAddNewItem2 () 210 { 211 Engine engine; 212 Project project; 213 214 engine = new Engine (Consts.BinPath); 215 project = engine.CreateNewProject (); 216 217 BuildItem item = project.AddNewItem ("A", "a;b;c"); 218 Assert.AreEqual ("a;b;c", item.Include, "A1"); 219 Assert.AreEqual ("a", item.FinalItemSpec, "A2"); 220 221 Assert.AreEqual (3, project.EvaluatedItems.Count, "A3"); 222 } 223 224 [Test] TestAddNewItem3()225 public void TestAddNewItem3 () 226 { 227 Engine engine; 228 Project project; 229 BuildItemGroup [] groups = new BuildItemGroup [4]; 230 231 string documentString = @" 232 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 233 <ItemGroup /> 234 <ItemGroup> 235 <A Include='a'/> 236 </ItemGroup> 237 <ItemGroup> 238 <B Include='a'/> 239 </ItemGroup> 240 <ItemGroup> 241 <B Include='a'/> 242 </ItemGroup> 243 </Project> 244 "; 245 246 engine = new Engine (Consts.BinPath); 247 project = engine.CreateNewProject (); 248 project.LoadXml (documentString); 249 250 project.AddNewItem ("B", "b"); 251 252 project.ItemGroups.CopyTo (groups, 0); 253 Assert.AreEqual (0, groups [0].Count, "A1"); 254 Assert.AreEqual (1, groups [1].Count, "A2"); 255 Assert.AreEqual (1, groups [2].Count, "A3"); 256 Assert.AreEqual (2, groups [3].Count, "A4"); 257 } 258 [Test] TestAddNewItemGroup()259 public void TestAddNewItemGroup () 260 { 261 Engine engine; 262 Project project; 263 264 string documentString = @" 265 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 266 </Project> 267 "; 268 269 engine = new Engine (Consts.BinPath); 270 project = engine.CreateNewProject (); 271 project.LoadXml (documentString); 272 273 BuildItemGroup big = project.AddNewItemGroup (); 274 Assert.IsNotNull (big, "A1"); 275 Assert.AreEqual (String.Empty, big.Condition, "A2"); 276 Assert.AreEqual (0, big.Count, "A3"); 277 Assert.AreEqual (false, big.IsImported, "A4"); 278 Assert.IsTrue (project.IsDirty, "A5"); 279 } 280 281 [Test] TestAddNewPropertyGroup()282 public void TestAddNewPropertyGroup () 283 { 284 Engine engine; 285 Project project; 286 287 string documentString = @" 288 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 289 </Project> 290 "; 291 292 engine = new Engine (Consts.BinPath); 293 project = engine.CreateNewProject (); 294 project.LoadXml (documentString); 295 296 BuildPropertyGroup bpg = project.AddNewPropertyGroup (false); 297 Assert.IsNotNull (bpg, "A1"); 298 Assert.AreEqual (String.Empty, bpg.Condition, "A2"); 299 Assert.AreEqual (0, bpg.Count, "A3"); 300 Assert.AreEqual (false, bpg.IsImported, "A4"); 301 Assert.IsTrue (project.IsDirty, "A5"); 302 } 303 304 [Test] TestBuild0()305 public void TestBuild0 () 306 { 307 Engine engine; 308 Project project; 309 IDictionary hashtable = new Hashtable (); 310 311 string documentString = @" 312 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 313 <Target 314 Name='Main' 315 Inputs='a;b;c' 316 Outputs='d;e;f' 317 > 318 </Target> 319 </Project> 320 "; 321 322 engine = new Engine (Consts.BinPath); 323 project = engine.CreateNewProject (); 324 project.LoadXml (documentString); 325 326 Assert.AreEqual (true, project.Build (new string [] { "Main" }, hashtable), "A1"); 327 Assert.AreEqual (1, hashtable.Count, "A2"); 328 329 IDictionaryEnumerator e = hashtable.GetEnumerator (); 330 e.MoveNext (); 331 332 string name = (string) e.Key; 333 Assert.AreEqual ("Main", name, "A3"); 334 ITaskItem [] arr = (ITaskItem []) e.Value; 335 336 Assert.AreEqual (3, arr.Length, "A4"); 337 Assert.AreEqual ("d", arr [0].ItemSpec, "A5"); 338 Assert.AreEqual ("e", arr [1].ItemSpec, "A6"); 339 Assert.AreEqual ("f", arr [2].ItemSpec, "A7"); 340 } 341 342 [Test] TestBuild1()343 public void TestBuild1 () 344 { 345 Engine engine; 346 Project project; 347 IDictionary hashtable = new Hashtable (); 348 349 string documentString = @" 350 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 351 <Target Name='Main'> 352 <Microsoft.Build.Tasks.Message Text='Text' /> 353 </Target> 354 </Project> 355 "; 356 357 engine = new Engine (Consts.BinPath); 358 project = engine.CreateNewProject (); 359 project.LoadXml (documentString); 360 361 Assert.AreEqual (true, project.Build (new string[] { "Main" }, hashtable), "A1"); 362 Assert.AreEqual (1, hashtable.Count, "A2"); 363 364 IDictionaryEnumerator e = hashtable.GetEnumerator (); 365 e.MoveNext (); 366 367 string name = (string) e.Key; 368 Assert.AreEqual ("Main", name, "A3"); 369 Assert.IsNotNull ((ITaskItem []) e.Value, "A4"); 370 } 371 372 [Test] TestBuild2()373 public void TestBuild2 () 374 { 375 Engine engine; 376 Project project; 377 378 string documentString = @" 379 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 380 <Target Name='T'> 381 <Message Text='text' /> 382 </Target> 383 </Project> 384 "; 385 386 engine = new Engine (Consts.BinPath); 387 MBT.TestMessageLogger tl = new MBT.TestMessageLogger(); 388 engine.RegisterLogger (tl); 389 project = engine.CreateNewProject (); 390 project.LoadXml (documentString); 391 392 project.Build ("T"); 393 project.Build ("T"); 394 395 Assert.AreEqual (2, tl.TargetStarted, "A1"); 396 Assert.AreEqual (2, tl.TargetFinished, "A2"); 397 Assert.AreEqual (2, tl.TaskStarted, "A3"); 398 Assert.AreEqual (2, tl.TaskFinished, "A4"); 399 } 400 401 [Test] TestBuild3()402 public void TestBuild3 () 403 { 404 Engine engine; 405 Project project; 406 407 string documentString = @" 408 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 409 <Target Name='T'> 410 <Message Text='text' /> 411 </Target> 412 </Project> 413 "; 414 415 engine = new Engine (Consts.BinPath); 416 MBT.TestMessageLogger tl = new MBT.TestMessageLogger (); 417 engine.RegisterLogger (tl); 418 project = engine.CreateNewProject (); 419 project.LoadXml (documentString); 420 421 project.Build (new string [1] { "T" }, null, BuildSettings.None); 422 project.Build (new string [1] { "T" }, null, BuildSettings.None); 423 424 Assert.AreEqual (2, tl.TargetStarted, "A1"); 425 Assert.AreEqual (2, tl.TargetFinished, "A2"); 426 Assert.AreEqual (2, tl.TaskStarted, "A3"); 427 Assert.AreEqual (2, tl.TaskFinished, "A4"); 428 } 429 430 [Test] TestBuild4()431 public void TestBuild4 () 432 { 433 Engine engine; 434 Project project; 435 436 string documentString = @" 437 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 438 <Target Name='T'> 439 <Message Text='text' /> 440 </Target> 441 </Project> 442 "; 443 444 engine = new Engine (Consts.BinPath); 445 MBT.TestMessageLogger tl = new MBT.TestMessageLogger (); 446 engine.RegisterLogger (tl); 447 project = engine.CreateNewProject (); 448 project.LoadXml (documentString); 449 450 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets); 451 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets); 452 453 Assert.AreEqual (1, tl.TargetStarted, "A1"); 454 Assert.AreEqual (1, tl.TargetFinished, "A2"); 455 Assert.AreEqual (1, tl.TaskStarted, "A3"); 456 Assert.AreEqual (1, tl.TaskFinished, "A4"); 457 } 458 459 [Test] TestBuild5()460 public void TestBuild5 () 461 { 462 Engine engine; 463 Project project; 464 465 string documentString = @" 466 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 467 </Project> 468 "; 469 470 engine = new Engine (Consts.BinPath); 471 project = engine.CreateNewProject (); 472 project.LoadXml (documentString); 473 474 Assert.IsFalse (project.Build ("target_that_doesnt_exist")); 475 } 476 477 [Test] TestEvaluatedItems1()478 public void TestEvaluatedItems1 () 479 { 480 Engine engine; 481 Project project; 482 483 string documentString = @" 484 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 485 <ItemGroup> 486 <A Include='a' /> 487 <B Include='b' Condition='false' /> 488 </ItemGroup> 489 </Project> 490 "; 491 492 engine = new Engine (Consts.BinPath); 493 project = engine.CreateNewProject (); 494 project.LoadXml (documentString); 495 496 Assert.AreEqual (1, project.EvaluatedItems.Count, "A1"); 497 498 BuildItem bi = project.EvaluatedItems [0]; 499 500 bi.Name = "C"; 501 bi.Include = "c"; 502 503 BuildItemGroup [] big = new BuildItemGroup [1]; 504 project.ItemGroups.CopyTo (big, 0); 505 Assert.AreEqual ("C", big [0] [0].Name, "A2"); 506 Assert.AreEqual ("c", big [0] [0].Include, "A3"); 507 } 508 509 [Test] TestEvaluatedItems2()510 public void TestEvaluatedItems2 () 511 { 512 Engine engine; 513 Project project; 514 515 string documentString = @" 516 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 517 <ItemGroup> 518 <A Include='a;b;c' /> 519 </ItemGroup> 520 </Project> 521 "; 522 523 engine = new Engine (Consts.BinPath); 524 project = engine.CreateNewProject (); 525 project.LoadXml (documentString); 526 527 BuildItemGroup [] big = new BuildItemGroup [1]; 528 project.ItemGroups.CopyTo (big, 0); 529 530 Assert.AreEqual (3, project.EvaluatedItems.Count, "A1"); 531 Assert.AreEqual ("a;b;c", big [0] [0].Include, "A2"); 532 Assert.AreEqual (1, big [0].Count, "A3"); 533 534 BuildItem bi = project.EvaluatedItems [0]; 535 536 bi.Include = "d"; 537 538 Assert.AreEqual (3, big [0].Count, "A4"); 539 Assert.AreEqual ("d", big [0] [0].Include, "A5"); 540 Assert.AreEqual ("b", big [0] [1].Include, "A6"); 541 Assert.AreEqual ("c", big [0] [2].Include, "A7"); 542 } 543 544 [Test] 545 [Category ("NotWorking")] TestGetConditionedPropertyValues()546 public void TestGetConditionedPropertyValues () 547 { 548 Engine engine; 549 Project project; 550 551 string documentString = @" 552 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 553 <PropertyGroup Condition='true'> 554 <A>A</A> 555 <B Condition='true'>A</B> 556 </PropertyGroup> 557 <PropertyGroup> 558 <C Condition='true'>A</C> 559 <C Condition='false'>B</C> 560 <C Condition='!false'>C</C> 561 <D>A</D> 562 <E Condition="" '$(C)' == 'A' "">E</E> 563 </PropertyGroup> 564 </Project> 565 "; 566 567 engine = new Engine (Consts.BinPath); 568 project = engine.CreateNewProject (); 569 project.LoadXml (documentString); 570 571 Assert.AreEqual (0, project.GetConditionedPropertyValues ("A").Length, "A1"); 572 Assert.AreEqual (0, project.GetConditionedPropertyValues ("B").Length, "A2"); 573 Assert.AreEqual (1, project.GetConditionedPropertyValues ("C").Length, "A3"); 574 Assert.AreEqual (0, project.GetConditionedPropertyValues ("D").Length, "A4"); 575 Assert.AreEqual (0, project.GetConditionedPropertyValues ("E").Length, "A5"); 576 Assert.AreEqual ("A", project.GetConditionedPropertyValues ("C") [0], "A6"); 577 } 578 579 [Test] 580 [ExpectedException (typeof (ArgumentNullException))] TestGetEvaluatedItemsByName1()581 public void TestGetEvaluatedItemsByName1 () 582 { 583 Engine engine; 584 Project project; 585 586 string documentString = @" 587 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 588 </Project> 589 "; 590 591 engine = new Engine (Consts.BinPath); 592 project = engine.CreateNewProject (); 593 project.LoadXml (documentString); 594 595 project.GetEvaluatedItemsByName (null); 596 } 597 598 [Test] TestGetEvaluatedItemsByName2()599 public void TestGetEvaluatedItemsByName2 () 600 { 601 Engine engine; 602 Project project; 603 604 string documentString = @" 605 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 606 <ItemGroup> 607 <A Include='1' /> 608 <B Include='2' Condition='true' /> 609 <C Include='3' Condition='false' /> 610 </ItemGroup> 611 </Project> 612 "; 613 614 engine = new Engine (Consts.BinPath); 615 project = engine.CreateNewProject (); 616 project.LoadXml (documentString); 617 618 BuildItemGroup big; 619 620 big = project.GetEvaluatedItemsByName (String.Empty); 621 622 Assert.AreEqual (0, big.Count, "A1"); 623 624 big = project.GetEvaluatedItemsByName ("A"); 625 626 Assert.AreEqual (1, big.Count, "A2"); 627 Assert.AreEqual ("1", big [0].FinalItemSpec, "A3"); 628 629 big = project.GetEvaluatedItemsByName ("B"); 630 631 Assert.AreEqual (1, big.Count, "A4"); 632 Assert.AreEqual ("2", big [0].FinalItemSpec, "A5"); 633 634 big = project.GetEvaluatedItemsByName ("C"); 635 636 Assert.AreEqual (0, big.Count, "A6"); 637 } 638 639 [Test] 640 [ExpectedException (typeof (ArgumentNullException))] TestGetEvaluatedItemsByNameIgnoringCondition1()641 public void TestGetEvaluatedItemsByNameIgnoringCondition1 () 642 { 643 Engine engine; 644 Project project; 645 646 string documentString = @" 647 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 648 </Project> 649 "; 650 651 engine = new Engine (Consts.BinPath); 652 project = engine.CreateNewProject (); 653 project.LoadXml (documentString); 654 655 project.GetEvaluatedItemsByNameIgnoringCondition (null); 656 } 657 658 [Test] TestGetEvaluatedItemsByNameIgnoringCondition2()659 public void TestGetEvaluatedItemsByNameIgnoringCondition2 () 660 { 661 Engine engine; 662 Project project; 663 664 string documentString = @" 665 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 666 <ItemGroup> 667 <A Include='1' /> 668 <B Include='2' Condition='true' /> 669 <C Include='3' Condition='false' /> 670 </ItemGroup> 671 </Project> 672 "; 673 674 engine = new Engine (Consts.BinPath); 675 project = engine.CreateNewProject (); 676 project.LoadXml (documentString); 677 678 BuildItemGroup big; 679 680 big = project.GetEvaluatedItemsByNameIgnoringCondition (String.Empty); 681 682 Assert.AreEqual (0, big.Count, "A1"); 683 684 big = project.GetEvaluatedItemsByNameIgnoringCondition ("A"); 685 686 Assert.AreEqual (1, big.Count, "A2"); 687 Assert.AreEqual ("1", big [0].FinalItemSpec, "A3"); 688 689 big = project.GetEvaluatedItemsByNameIgnoringCondition ("B"); 690 691 Assert.AreEqual (1, big.Count, "A4"); 692 Assert.AreEqual ("2", big [0].FinalItemSpec, "A5"); 693 694 big = project.GetEvaluatedItemsByNameIgnoringCondition ("C"); 695 696 Assert.AreEqual (1, big.Count, "A6"); 697 Assert.AreEqual ("3", big [0].FinalItemSpec, "A7"); 698 } 699 700 [Test] 701 [ExpectedException (typeof (ArgumentNullException))] TestGetEvaluatedProperty1()702 public void TestGetEvaluatedProperty1 () 703 { 704 Engine engine; 705 Project project; 706 707 string documentString = @" 708 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 709 </Project> 710 "; 711 712 engine = new Engine (Consts.BinPath); 713 project = engine.CreateNewProject (); 714 project.LoadXml (documentString); 715 716 project.GetEvaluatedProperty (null); 717 } 718 [Test] TestGetEvaluatedProperty2()719 public void TestGetEvaluatedProperty2 () 720 { 721 Engine engine; 722 Project project; 723 724 string documentString = @" 725 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 726 <PropertyGroup> 727 <A>1</A> 728 <B Condition='true'>2</B> 729 <C Condition='false'>3</C> 730 </PropertyGroup> 731 </Project> 732 "; 733 734 engine = new Engine (Consts.BinPath); 735 project = engine.CreateNewProject (); 736 project.LoadXml (documentString); 737 738 Assert.AreEqual ("1", project.GetEvaluatedProperty ("A"), "A1"); 739 Assert.AreEqual ("2", project.GetEvaluatedProperty ("B"), "A2"); 740 Assert.IsNull (project.GetEvaluatedProperty ("C"), "A3"); 741 } 742 743 [Test] TestGetProjectExtensions()744 public void TestGetProjectExtensions () 745 { 746 Engine engine; 747 Project project; 748 749 string documentString = @" 750 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 751 <ProjectExtensions> 752 <Node>Text</Node> 753 </ProjectExtensions> 754 </Project> 755 "; 756 757 engine = new Engine (Consts.BinPath); 758 project = engine.CreateNewProject (); 759 project.LoadXml (documentString); 760 761 Assert.AreEqual (String.Empty, project.GetProjectExtensions (null), "A1"); 762 Assert.AreEqual (String.Empty, project.GetProjectExtensions (String.Empty), "A2"); 763 Assert.AreEqual (String.Empty, project.GetProjectExtensions ("something"), "A3"); 764 Assert.AreEqual ("Text", project.GetProjectExtensions ("Node"), "A4"); 765 } 766 767 [Test] TestGlobalProperties1()768 public void TestGlobalProperties1 () 769 { 770 Engine engine; 771 Project project; 772 773 string documentString = @" 774 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 775 </Project> 776 "; 777 778 engine = new Engine (Consts.BinPath); 779 project = engine.CreateNewProject (); 780 project.LoadXml (documentString); 781 782 Assert.AreEqual (0, project.GlobalProperties.Count, "A1"); 783 } 784 785 [Test] TestGlobalProperties2()786 public void TestGlobalProperties2 () 787 { 788 Engine engine; 789 Project project; 790 791 string documentString = @" 792 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 793 </Project> 794 "; 795 796 engine = new Engine (Consts.BinPath); 797 engine.GlobalProperties.SetProperty ("Property", "Value"); 798 799 project = engine.CreateNewProject (); 800 project.LoadXml (documentString); 801 802 Assert.AreEqual (1, project.GlobalProperties.Count, "A1"); 803 Assert.AreEqual ("Property", project.GlobalProperties ["Property"].Name, "A2"); 804 Assert.AreEqual ("Value", project.GlobalProperties ["Property"].Value, "A3"); 805 Assert.AreEqual ("Value", project.GlobalProperties ["Property"].FinalValue, "A4"); 806 Assert.AreEqual ("Property", project.EvaluatedProperties ["Property"].Name, "A2"); 807 Assert.AreEqual ("Value", project.EvaluatedProperties ["Property"].Value, "A3"); 808 Assert.AreEqual ("Value", project.EvaluatedProperties ["Property"].FinalValue, "A4"); 809 } 810 811 [Test] 812 [Category ("NotDotNet")] 813 [ExpectedException (typeof (ArgumentNullException))] TestGlobalProperties3()814 public void TestGlobalProperties3 () 815 { 816 Engine engine; 817 Project project; 818 819 string documentString = @" 820 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 821 </Project> 822 "; 823 824 engine = new Engine (Consts.BinPath); 825 project = engine.CreateNewProject (); 826 project.LoadXml (documentString); 827 828 project.GlobalProperties = null; 829 } 830 831 [Test] 832 [Ignore ("needs rewriting")] TestGlobalProperties4()833 public void TestGlobalProperties4 () 834 { 835 Engine engine; 836 Project project; 837 838 string documentString = @" 839 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 840 <PropertyGroup> 841 <Property>a</Property> 842 </PropertyGroup> 843 </Project> 844 "; 845 846 engine = new Engine (Consts.BinPath); 847 project = engine.CreateNewProject (); 848 project.LoadXml (documentString); 849 850 BuildPropertyGroup[] groups = new BuildPropertyGroup [1]; 851 project.PropertyGroups.CopyTo (groups, 0); 852 853 project.GlobalProperties = groups [0]; 854 project.GlobalProperties = project.EvaluatedProperties; 855 } 856 857 [Test] 858 [Category ("NotDotNet")] 859 [ExpectedException (typeof (InvalidOperationException))] TestGlobalProperties5()860 public void TestGlobalProperties5 () 861 { 862 Engine engine; 863 Project project; 864 865 string documentString = @" 866 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 867 <PropertyGroup> 868 <Property>a</Property> 869 </PropertyGroup> 870 </Project> 871 "; 872 873 engine = new Engine (Consts.BinPath); 874 project = engine.CreateNewProject (); 875 project.LoadXml (documentString); 876 877 BuildPropertyGroup[] groups = new BuildPropertyGroup [1]; 878 project.PropertyGroups.CopyTo (groups, 0); 879 project.GlobalProperties = groups [0]; 880 } 881 882 [Test] 883 [ExpectedException (typeof (InvalidProjectFileException))] TestLoad1()884 public void TestLoad1 () 885 { 886 Engine engine; 887 Project project; 888 889 string documentString = @" 890 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 891 <PropertyGroup> 892 </Project> 893 "; 894 895 engine = new Engine (Consts.BinPath); 896 project = engine.CreateNewProject (); 897 project.LoadXml (documentString); 898 } 899 900 [Test] 901 [ExpectedException (typeof (InvalidProjectFileException))] TestLoad2()902 public void TestLoad2 () 903 { 904 Engine engine; 905 Project project; 906 907 engine = new Engine (Consts.BinPath); 908 project = engine.CreateNewProject (); 909 project.LoadXml ("project_file_that_doesnt_exist"); 910 } 911 912 [Test] TestParentEngine()913 public void TestParentEngine () 914 { 915 Engine engine; 916 Project project; 917 918 engine = new Engine (Consts.BinPath); 919 project = engine.CreateNewProject (); 920 921 Assert.AreEqual (engine, project.ParentEngine, "A1"); 922 } 923 924 [Test] 925 [Category ("NotDotNet")] 926 [ExpectedException (typeof (ArgumentNullException))] TestRemoveItemGroup1()927 public void TestRemoveItemGroup1 () 928 { 929 Engine engine; 930 Project p1; 931 932 engine = new Engine (Consts.BinPath); 933 p1 = engine.CreateNewProject (); 934 935 p1.RemoveItemGroup (null); 936 } 937 938 // The "BuildItemGroup" object specified does not belong to the correct "Project" object. 939 [Test] 940 [ExpectedException (typeof (InvalidOperationException))] 941 [Category ("NotWorking")] TestRemoveItemGroup2()942 public void TestRemoveItemGroup2 () 943 { 944 Engine engine; 945 Project p1; 946 Project p2; 947 BuildItemGroup [] groups = new BuildItemGroup [1]; 948 949 engine = new Engine (Consts.BinPath); 950 p1 = engine.CreateNewProject (); 951 p2 = engine.CreateNewProject (); 952 953 p1.AddNewItem ("A", "B"); 954 p1.ItemGroups.CopyTo (groups, 0); 955 956 p2.RemoveItemGroup (groups [0]); 957 } 958 959 [Test] 960 [Category ("NotDotNet")] 961 [ExpectedException (typeof (ArgumentNullException))] TestRemoveItem1()962 public void TestRemoveItem1 () 963 { 964 Engine engine; 965 Project project; 966 967 engine = new Engine (Consts.BinPath); 968 project = engine.CreateNewProject (); 969 970 project.RemoveItem (null); 971 } 972 973 // The object passed in is not part of the project. 974 [Test] 975 [ExpectedException (typeof (InvalidOperationException))] TestRemoveItem2()976 public void TestRemoveItem2 () 977 { 978 Engine engine; 979 Project project; 980 981 engine = new Engine (Consts.BinPath); 982 project = engine.CreateNewProject (); 983 984 project.RemoveItem (new BuildItem ("name", "include")); 985 } 986 987 // The "BuildItemGroup" object specified does not belong to the correct "Project" object. 988 [Test] 989 [ExpectedException (typeof (InvalidOperationException))] TestRemoveItem3()990 public void TestRemoveItem3 () 991 { 992 Engine engine; 993 Project p1; 994 Project p2; 995 996 engine = new Engine (Consts.BinPath); 997 p1 = engine.CreateNewProject (); 998 p2 = engine.CreateNewProject (); 999 1000 p1.AddNewItem ("A", "B"); 1001 1002 p2.RemoveItem (p1.EvaluatedItems [0]); 1003 } 1004 1005 [Test] 1006 [Category ("NotDotNet")] 1007 [ExpectedException (typeof (InvalidOperationException))] TestRemoveItem4()1008 public void TestRemoveItem4 () 1009 { 1010 Engine engine; 1011 Project p1; 1012 Project p2; 1013 1014 engine = new Engine (Consts.BinPath); 1015 p1 = engine.CreateNewProject (); 1016 p2 = engine.CreateNewProject (); 1017 1018 p1.AddNewItem ("A", "B"); 1019 p1.AddNewItem ("A", "C"); 1020 1021 p2.RemoveItem (p1.EvaluatedItems [0]); 1022 } 1023 1024 [Test] TestRemoveItem5()1025 public void TestRemoveItem5 () 1026 { 1027 Engine engine; 1028 Project project; 1029 BuildItemGroup [] groups = new BuildItemGroup [1]; 1030 1031 string documentString = @" 1032 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 1033 <ItemGroup> 1034 <A Include='a'/> 1035 </ItemGroup> 1036 </Project> 1037 "; 1038 1039 engine = new Engine (Consts.BinPath); 1040 project = engine.CreateNewProject (); 1041 project.LoadXml (documentString); 1042 1043 project.RemoveItem (project.EvaluatedItems [0]); 1044 Assert.AreEqual (0, project.EvaluatedItems.Count, "A1"); 1045 project.ItemGroups.CopyTo (groups, 0); 1046 Assert.IsNull (groups [0], "A2"); 1047 Assert.AreEqual (0, project.ItemGroups.Count, "A3"); 1048 } 1049 1050 [Test] TestResetBuildStatus()1051 public void TestResetBuildStatus () 1052 { 1053 Engine engine; 1054 Project project; 1055 1056 string documentString = @" 1057 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 1058 <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'> 1059 <Message Text='text' /> 1060 </Target> 1061 </Project> 1062 "; 1063 1064 engine = new Engine (Consts.BinPath); 1065 TestLogger tl = new TestLogger (); 1066 engine.RegisterLogger (tl); 1067 project = engine.CreateNewProject (); 1068 project.LoadXml (documentString); 1069 1070 project.Build ("T"); 1071 project.ResetBuildStatus (); 1072 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets); 1073 project.ResetBuildStatus (); 1074 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets); 1075 1076 Assert.AreEqual (3, tl.TargetStartedEvents, "A1"); 1077 Assert.AreEqual (3, tl.TargetFinishedEvents, "A1"); 1078 } 1079 1080 [Test] TestSchemaFile()1081 public void TestSchemaFile () 1082 { 1083 Engine engine; 1084 Project project; 1085 1086 string documentString = @" 1087 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 1088 </Project> 1089 "; 1090 1091 engine = new Engine (Consts.BinPath); 1092 project = engine.CreateNewProject (); 1093 project.LoadXml (documentString); 1094 1095 Assert.IsNull (project.SchemaFile, "A1"); 1096 } 1097 [Test] 1098 [Category ("NotDotNet")] 1099 [ExpectedException (typeof (ArgumentNullException))] TestSetProjectExtensions1()1100 public void TestSetProjectExtensions1 () 1101 { 1102 Engine engine; 1103 Project project; 1104 1105 string documentString = @" 1106 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 1107 </Project> 1108 "; 1109 1110 engine = new Engine (Consts.BinPath); 1111 project = engine.CreateNewProject (); 1112 project.LoadXml (documentString); 1113 1114 project.SetProjectExtensions (null, null); 1115 } 1116 1117 [Test] TestSetProjectExtensions2()1118 public void TestSetProjectExtensions2 () 1119 { 1120 Engine engine; 1121 Project project; 1122 1123 string documentString = @" 1124 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 1125 </Project> 1126 "; 1127 1128 engine = new Engine (Consts.BinPath); 1129 project = engine.CreateNewProject (); 1130 project.LoadXml (documentString); 1131 1132 project.SetProjectExtensions ("name", "1"); 1133 Assert.AreEqual ("1", project.GetProjectExtensions ("name"), "A1"); 1134 project.SetProjectExtensions ("name", "2"); 1135 Assert.AreEqual ("2", project.GetProjectExtensions ("name"), "A2"); 1136 Assert.IsTrue (project.IsDirty, "A3"); 1137 } 1138 1139 [Test] TestSetProjectExtensions3()1140 public void TestSetProjectExtensions3 () 1141 { 1142 Engine engine; 1143 Project project; 1144 1145 string documentString = @" 1146 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> 1147 <ProjectExtensions> 1148 </ProjectExtensions> 1149 </Project> 1150 "; 1151 1152 engine = new Engine (Consts.BinPath); 1153 project = engine.CreateNewProject (); 1154 project.LoadXml (documentString); 1155 1156 project.SetProjectExtensions ("name", "1"); 1157 Assert.AreEqual ("1", project.GetProjectExtensions ("name"), "A1"); 1158 Assert.IsTrue (project.IsDirty, "A2"); 1159 } 1160 1161 [Test] TestBuildProjectError1()1162 public void TestBuildProjectError1 () 1163 { 1164 Engine engine = new Engine (Consts.BinPath); 1165 Project project = engine.CreateNewProject (); 1166 1167 Assert.IsFalse (project.Build ((string) null), "A1"); 1168 Assert.IsFalse (project.Build ((string[]) null), "A2"); 1169 Assert.IsFalse (project.Build ((string []) null, null), "A3"); 1170 Assert.IsFalse (project.Build ((string []) null, null, BuildSettings.None), "A4"); 1171 } 1172 1173 [Test] TestBuildProjectError2()1174 public void TestBuildProjectError2 () 1175 { 1176 Engine engine = new Engine (Consts.BinPath); 1177 Project project = engine.CreateNewProject (); 1178 1179 try { 1180 project.Build (new string [] { null }); 1181 } catch { 1182 return; 1183 } 1184 Assert.Fail ("Expected exception for project.Build, null string in targetNames []"); 1185 } 1186 1187 [Test] TestBuildProjectFile1()1188 public void TestBuildProjectFile1 () 1189 { 1190 Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2" }, new bool [] { true, true }, "TBPF1"); 1191 CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPF1"); 1192 } 1193 1194 [Test] TestBuildProjectFileXml1()1195 public void TestBuildProjectFileXml1 () 1196 { 1197 Project project = CreateAndLoadProject (null, false, new string [] { "1", "2" }, new bool [] { true, true }, "TBPFX1"); 1198 CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPFX1"); 1199 } 1200 1201 [Test] TestBuildProjectFile2()1202 public void TestBuildProjectFile2 () 1203 { 1204 Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPF2"); 1205 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPF2"); 1206 } 1207 1208 [Test] TestBuildProjectFileXml2()1209 public void TestBuildProjectFileXml2 () 1210 { 1211 Project project = CreateAndLoadProject (null, false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPFX2"); 1212 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPFX2"); 1213 } 1214 1215 [Test] TestBuildProjectFile3()1216 public void TestBuildProjectFile3 () 1217 { 1218 Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPF3"); 1219 CheckProjectBuild (project, new string [] { "1", "2" }, true, new string [] { "1", "2" }, "TBPF3"); 1220 } 1221 1222 [Test] TestBuildProjectFileXml3()1223 public void TestBuildProjectFileXml3 () 1224 { 1225 Project project = CreateAndLoadProject (null, false, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPFX3"); 1226 CheckProjectBuild (project, new string [] { "1", "2" }, true, new string [] { "1", "2" }, "TBPFX3"); 1227 } 1228 1229 [Test] TestBuildProjectFile4()1230 public void TestBuildProjectFile4 () 1231 { 1232 Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPF4"); 1233 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPF4"); 1234 } 1235 1236 [Test] TestBuildProjectFileXml4()1237 public void TestBuildProjectFileXml4 () 1238 { 1239 Project project = CreateAndLoadProject (null, false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPFX4"); 1240 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPFX4"); 1241 } 1242 1243 //Run separate tests 1244 1245 //Run single target 1246 [Test] TestBuildProjectFile5()1247 public void TestBuildProjectFile5 () 1248 { 1249 Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPF5"); 1250 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPF5"); 1251 } 1252 1253 [Test] TestBuildProjectFileXml5()1254 public void TestBuildProjectFileXml5 () 1255 { 1256 Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPFX5"); 1257 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPFX5"); 1258 } 1259 1260 [Test] TestBuildProjectFile6()1261 public void TestBuildProjectFile6 () 1262 { 1263 Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPF6"); 1264 CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPF6"); 1265 } 1266 1267 [Test] TestBuildProjectFileXml6()1268 public void TestBuildProjectFileXml6 () 1269 { 1270 Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPFX6"); 1271 CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPFX6"); 1272 } 1273 1274 // run multiple targets 1275 [Test] TestBuildProjectFile7()1276 public void TestBuildProjectFile7 () 1277 { 1278 Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPF7"); 1279 CheckProjectBuild (project, new string [] { "1", "2", "3" }, true, new string [] { "1", "2", "3" }, "TBPF7"); 1280 } 1281 1282 [Test] TestBuildProjectFileXml7()1283 public void TestBuildProjectFileXml7 () 1284 { 1285 Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPFX7"); 1286 CheckProjectBuild (project, new string [] { "1", "2", "3" }, true, new string [] { "1", "2", "3" }, "TBPFX7"); 1287 } 1288 1289 [Test] TestBuildProjectFile8()1290 public void TestBuildProjectFile8 () 1291 { 1292 Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, true, false }, "TBPF8"); 1293 CheckProjectBuild (project, new string [] { "1", "2", "3" }, false, new string [] { "1", "2"}, "TBPF8"); 1294 } 1295 1296 [Test] TestBuildProjectFileXml8()1297 public void TestBuildProjectFileXml8 () 1298 { 1299 Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, true, false }, "TBPFX8"); 1300 CheckProjectBuild (project, new string [] { "1", "2", "3" }, false, new string [] { "1", "2"}, "TBPFX8"); 1301 } 1302 1303 [Test] 1304 [Category ("NotDotNet")] TestBatchedMetadataRef1()1305 public void TestBatchedMetadataRef1 () 1306 { 1307 //test for multiple items with same metadata also 1308 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> 1309 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" /> 1310 <ItemGroup> 1311 <Coll1 Include=""A1""><Name>Abc</Name></Coll1> 1312 <Coll1 Include=""A2""><Name>Def</Name></Coll1> 1313 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1> 1314 <Coll1 Include=""A4""><Name>Xyz</Name></Coll1> 1315 <Coll2 Include=""B1""></Coll2> 1316 </ItemGroup> 1317 <Target Name=""ShowMessage""> 1318 <BatchingTestTask Sources=""%(Coll1.Name)""> 1319 <Output TaskParameter=""Output"" ItemName=""FinalList"" /> 1320 </BatchingTestTask> 1321 <Message Text=""Msg: %(Coll1.Name)"" /> 1322 </Target> 1323 </Project>"; 1324 1325 Engine engine = new Engine (Consts.BinPath); 1326 Project project = engine.CreateNewProject (); 1327 1328 project.LoadXml (projectString); 1329 Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed"); 1330 1331 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList"); 1332 Assert.AreEqual (3, include.Count, "A2"); 1333 1334 Assert.AreEqual ("FinalList", include [0].Name, "A3"); 1335 Assert.AreEqual ("Abc", include [0].FinalItemSpec, "A4"); 1336 1337 Assert.AreEqual ("FinalList", include [1].Name, "A5"); 1338 Assert.AreEqual ("Def", include [1].FinalItemSpec, "A6"); 1339 1340 Assert.AreEqual ("FinalList", include [2].Name, "A7"); 1341 Assert.AreEqual ("Xyz", include [2].FinalItemSpec, "A8"); 1342 } 1343 1344 [Test] 1345 [Category ("NotDotNet")] TestBatchedMetadataRef2()1346 public void TestBatchedMetadataRef2 () 1347 { 1348 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> 1349 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" /> 1350 <ItemGroup> 1351 <Coll1 Include=""A1""><Name>Abc</Name></Coll1> 1352 <Coll1 Include=""A2""><Name>Def</Name></Coll1> 1353 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1> 1354 <Coll1 Include=""A4""><Name>Abc</Name></Coll1> 1355 <Coll2 Include=""B1""><Name>Bar</Name></Coll2> 1356 <Coll2 Include=""B2""><Name>Bar</Name></Coll2> 1357 </ItemGroup> 1358 <Target Name=""ShowMessage""> 1359 <BatchingTestTask Sources=""%(Name)"" Strings=""@(Coll2)""> 1360 <Output TaskParameter=""Output"" ItemName=""FinalList"" /> 1361 </BatchingTestTask> 1362 <Message Text=""Msg: %(Coll1.Name)"" /> 1363 </Target> 1364 <Target Name=""ShowMessage2""> 1365 <BatchingTestTask Sources=""%(Name)"" Strings=""@(Coll1)""> 1366 <Output TaskParameter=""Output"" ItemName=""FinalList2"" /> 1367 </BatchingTestTask> 1368 <Message Text=""Msg: %(Coll1.Name)"" /> 1369 </Target> 1370 </Project>"; 1371 1372 Engine engine = new Engine (Consts.BinPath); 1373 Project project = engine.CreateNewProject (); 1374 1375 project.LoadXml (projectString); 1376 Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed"); 1377 1378 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList"); 1379 Assert.AreEqual (1, include.Count, "A2"); 1380 1381 Assert.AreEqual ("FinalList", include [0].Name, "A3"); 1382 Assert.AreEqual ("Bar", include [0].FinalItemSpec, "A4"); 1383 1384 Assert.IsTrue (project.Build ("ShowMessage2"), "A1: Build failed"); 1385 include = project.GetEvaluatedItemsByName ("FinalList2"); 1386 Assert.AreEqual (3, include.Count, "A5"); 1387 1388 Assert.AreEqual ("FinalList2", include [0].Name, "A6"); 1389 Assert.AreEqual ("Abc", include [0].FinalItemSpec, "A7"); 1390 1391 Assert.AreEqual ("FinalList2", include [1].Name, "A8"); 1392 Assert.AreEqual ("Def", include [1].FinalItemSpec, "A9"); 1393 1394 Assert.AreEqual ("FinalList2", include [2].Name, "A10"); 1395 Assert.AreEqual ("Xyz", include [2].FinalItemSpec, "A11"); 1396 } 1397 1398 [Test] 1399 [Category ("NotDotNet")] TestBatchedMetadataRef3()1400 public void TestBatchedMetadataRef3 () 1401 { 1402 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> 1403 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" /> 1404 <ItemGroup> 1405 <Coll1 Include=""A1""><Name>Abc</Name></Coll1> 1406 <Coll1 Include=""A2""><Name>Def</Name></Coll1> 1407 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1> 1408 <Coll1 Include=""A4""><Name>Abc</Name></Coll1> 1409 <Coll2 Include=""B1""><Name>Bar</Name></Coll2> 1410 <Coll2 Include=""B2""><Name>Bar</Name></Coll2> 1411 </ItemGroup> 1412 <Target Name=""ShowMessage""> 1413 <BatchingTestTask SingleTaskItem=""%(Coll2.Name)"" > 1414 <Output TaskParameter=""SingleStringOutput"" ItemName=""FinalList"" /> 1415 </BatchingTestTask> 1416 <Message Text=""Msg: %(Coll1.Name)"" /> 1417 </Target> 1418 </Project>"; 1419 1420 Engine engine = new Engine (Consts.BinPath); 1421 Project project = engine.CreateNewProject (); 1422 1423 project.LoadXml (projectString); 1424 Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed"); 1425 1426 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList"); 1427 Assert.AreEqual (1, include.Count, "A2"); 1428 1429 Assert.AreEqual ("FinalList", include [0].Name, "A3"); 1430 Assert.AreEqual ("Bar", include [0].FinalItemSpec, "A4"); 1431 1432 } 1433 1434 [Test] 1435 [Category ("NotDotNet")] TestBatchedMetadataRef4()1436 public void TestBatchedMetadataRef4 () 1437 { 1438 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> 1439 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" /> 1440 <ItemGroup> 1441 <Coll1 Include=""A1""><Name>Abc</Name></Coll1> 1442 <Coll1 Include=""A2""><Name>Def</Name></Coll1> 1443 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1> 1444 <Coll2 Include=""B1""><Name>Bar</Name></Coll2> 1445 </ItemGroup> 1446 <Target Name=""ShowMessage""> 1447 <BatchingTestTask SingleTaskItem=""%(Coll3.Name)"" > 1448 <Output TaskParameter=""SingleStringOutput"" ItemName=""FinalList"" /> 1449 </BatchingTestTask> 1450 </Target> 1451 </Project>"; 1452 1453 Engine engine = new Engine (Consts.BinPath); 1454 Project project = engine.CreateNewProject (); 1455 1456 project.LoadXml (projectString); 1457 Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed"); 1458 1459 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList"); 1460 Assert.AreEqual (0, include.Count, "A2"); 1461 } 1462 1463 [Test] 1464 [Category ("NotDotNet")] TestBatchedMetadataRef5()1465 public void TestBatchedMetadataRef5 () 1466 { 1467 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> 1468 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" /> 1469 <ItemGroup> 1470 <Coll1 Include=""A1""><Name>Abc</Name></Coll1> 1471 <Coll1 Include=""A2""><Name>Def</Name></Coll1> 1472 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1> 1473 <Coll2 Include=""B1""><Name>Bar</Name></Coll2> 1474 </ItemGroup> 1475 <Target Name=""ShowMessage""> 1476 <Message Text=""Coll1: @(Coll1->'Foo%(Name)Bar')"" /> 1477 <BatchingTestTask Sources=""@(Coll1->'Foo%(Name)Bar')"" > 1478 <Output TaskParameter=""Output"" ItemName=""FinalList"" /> 1479 </BatchingTestTask> 1480 </Target> 1481 </Project>"; 1482 1483 Engine engine = new Engine (Consts.BinPath); 1484 Project project = engine.CreateNewProject (); 1485 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = 1486 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); 1487 engine.RegisterLogger (logger); 1488 1489 project.LoadXml (projectString); 1490 bool result = project.Build ("ShowMessage"); 1491 if (!result) { 1492 logger.DumpMessages (); 1493 Assert.Fail ("A1: Build failed"); 1494 } 1495 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList"); 1496 Assert.AreEqual (3, include.Count, "A2"); 1497 } 1498 1499 [Test] 1500 [Category ("NotDotNet")] TestBatchedMetadataRefInOutput()1501 public void TestBatchedMetadataRefInOutput () { 1502 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> 1503 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" /> 1504 <ItemGroup> 1505 <Coll1 Include=""A1""><Name>Abc</Name></Coll1> 1506 <Coll1 Include=""A2""><Name>Def</Name></Coll1> 1507 <Coll1 Include=""A3""><Name>Abc</Name></Coll1> 1508 <Coll1 Include=""B1""><Name>Bar</Name></Coll1> 1509 </ItemGroup> 1510 <Target Name=""ShowMessage""> 1511 <BatchingTestTask Sources=""@(Coll1)"" > 1512 <Output TaskParameter=""Output"" ItemName=""AbcItems"" Condition=""'%(Coll1.Name)' == 'Abc'""/> 1513 <Output TaskParameter=""Output"" ItemName=""NonAbcItems"" Condition=""'%(Coll1.Name)' != 'Abc'""/> 1514 </BatchingTestTask> 1515 <Message Text='AbcItems: @(AbcItems)' /> 1516 <Message Text='NonAbcItems: @(NonAbcItems)' /> 1517 </Target> 1518 </Project>"; 1519 1520 Engine engine = new Engine (Consts.BinPath); 1521 Project project = engine.CreateNewProject (); 1522 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = 1523 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); 1524 engine.RegisterLogger (logger); 1525 1526 project.LoadXml (projectString); 1527 bool result = project.Build ("ShowMessage"); 1528 if (!result) { 1529 logger.DumpMessages (); 1530 Assert.Fail ("A1: Build failed"); 1531 } 1532 1533 logger.CheckLoggedMessageHead ("AbcItems: A1;A3", "A2"); 1534 logger.CheckLoggedMessageHead ("NonAbcItems: A2;B1", "A2"); 1535 1536 if (logger.NormalMessageCount != 0) { 1537 logger.DumpMessages (); 1538 Assert.Fail ("Unexpected extra messages found"); 1539 } 1540 } 1541 1542 [Test] TestInitialTargets()1543 public void TestInitialTargets () 1544 { 1545 Engine engine = new Engine (Consts.BinPath); 1546 Project project = engine.CreateNewProject (); 1547 1548 project.LoadXml (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" InitialTargets=""pre ""> 1549 <Target Name=""boo""> 1550 <Message Text=""Executing boo target""/> 1551 </Target> 1552 <Target Name=""pre""> 1553 <Message Text=""Executing pre target""/> 1554 </Target> 1555 </Project>"); 1556 1557 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = 1558 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); 1559 engine.RegisterLogger (logger); 1560 1561 try { 1562 Assert.IsTrue (project.Build (), "Build failed"); 1563 1564 logger.CheckLoggedMessageHead ("Executing pre target", "A1"); 1565 logger.CheckLoggedMessageHead ("Executing boo target", "A2"); 1566 1567 Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found"); 1568 } catch { 1569 logger.DumpMessages (); 1570 throw; 1571 } 1572 } 1573 1574 [Test] TestInitialTargetsWithImports()1575 public void TestInitialTargetsWithImports () { 1576 Engine engine = new Engine (Consts.BinPath); 1577 Project project = engine.CreateNewProject (); 1578 1579 string second = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" InitialTargets=""One ""> 1580 <Target Name=""One""> 1581 <Message Text='Executing Second::One target'/> 1582 </Target> 1583 <Import Project='third.proj'/> 1584 </Project> 1585 "; 1586 using (StreamWriter sw = new StreamWriter (Path.Combine ("Test", Path.Combine ("resources", "second.proj")))) { 1587 sw.Write (second); 1588 } 1589 1590 string third = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" InitialTargets=""Two""> 1591 <Target Name=""Two""> 1592 <Message Text='Executing Third::Two target'/> 1593 </Target> 1594 </Project> 1595 "; 1596 using (StreamWriter sw = new StreamWriter (Path.Combine ("Test", Path.Combine ("resources", "third.proj")))) { 1597 sw.Write (third); 1598 } 1599 1600 project.LoadXml (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" InitialTargets=""pre""> 1601 <Target Name=""boo""> 1602 <Message Text=""Executing boo target""/> 1603 </Target> 1604 <Target Name=""pre""> 1605 <Message Text=""Executing pre target""/> 1606 </Target> 1607 <Import Project='Test/resources/second.proj'/> 1608 </Project>"); 1609 1610 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = 1611 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); 1612 engine.RegisterLogger (logger); 1613 1614 try { 1615 Assert.IsTrue (project.Build (), "Build failed"); 1616 1617 logger.CheckLoggedMessageHead ("Executing pre target", "A1"); 1618 logger.CheckLoggedMessageHead ("Executing Second::One target", "A2"); 1619 logger.CheckLoggedMessageHead ("Executing Third::Two target", "A3"); 1620 logger.CheckLoggedMessageHead ("Executing boo target", "A4"); 1621 Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found"); 1622 1623 Assert.AreEqual ("pre; One; Two", project.InitialTargets, "List of initial targets"); 1624 } catch { 1625 logger.DumpMessages (); 1626 throw; 1627 } 1628 } 1629 1630 [Test] TestDefaultTargets()1631 public void TestDefaultTargets () { 1632 Engine engine = new Engine (Consts.BinPath); 1633 Project project = engine.CreateNewProject (); 1634 1635 project.LoadXml (@"<Project DefaultTargets='pre' xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" > 1636 <Target Name=""boo""> 1637 <Message Text=""Executing boo target""/> 1638 </Target> 1639 <Target Name=""pre""> 1640 <Message Text=""Executing pre target""/> 1641 </Target> 1642 </Project>"); 1643 1644 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = 1645 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); 1646 engine.RegisterLogger (logger); 1647 1648 try { 1649 Assert.IsTrue (project.Build (), "Build failed"); 1650 1651 logger.CheckLoggedMessageHead ("Executing pre target", "A1"); 1652 Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found"); 1653 1654 Assert.AreEqual ("pre", project.DefaultTargets, "Default targets"); 1655 } catch { 1656 logger.DumpMessages (); 1657 throw; 1658 } 1659 } 1660 1661 1662 [Test] TestDefaultTargetsWithImports()1663 public void TestDefaultTargetsWithImports () { 1664 Engine engine = new Engine (Consts.BinPath); 1665 Project project = engine.CreateNewProject (); 1666 1667 string second = @"<Project DefaultTargets='One' xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> 1668 <Target Name=""One""> 1669 <Message Text='Executing Second::One target'/> 1670 </Target> 1671 </Project>"; 1672 using (StreamWriter sw = new StreamWriter (Path.Combine ("Test", Path.Combine ("resources", "second.proj")))) { 1673 sw.Write (second); 1674 } 1675 1676 project.LoadXml (@"<Project DefaultTargets='pre' xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" > 1677 <Target Name=""boo""> 1678 <Message Text=""Executing boo target""/> 1679 </Target> 1680 <Target Name=""pre""> 1681 <Message Text=""Executing pre target""/> 1682 </Target> 1683 <Import Project='Test/resources/second.proj'/> 1684 </Project>"); 1685 1686 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = 1687 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); 1688 engine.RegisterLogger (logger); 1689 1690 try { 1691 Assert.IsTrue (project.Build (), "Build failed"); 1692 1693 logger.CheckLoggedMessageHead ("Executing pre target", "A1"); 1694 Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found"); 1695 1696 Assert.AreEqual ("pre", project.DefaultTargets, "Default targets"); 1697 } catch { 1698 logger.DumpMessages (); 1699 throw; 1700 } 1701 } 1702 1703 [Test] TestNoDefaultTargetsWithImports()1704 public void TestNoDefaultTargetsWithImports () { 1705 Engine engine = new Engine (Consts.BinPath); 1706 Project project = engine.CreateNewProject (); 1707 1708 1709 string second = @"<Project DefaultTargets='; One ; Two' xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> 1710 <Target Name=""One""> 1711 <Message Text='Executing Second::One target'/> 1712 </Target> 1713 <Target Name=""Two""> 1714 <Message Text='Executing Second::Two target'/> 1715 </Target> 1716 1717 </Project>"; 1718 using (StreamWriter sw = new StreamWriter (Path.Combine ("Test", Path.Combine ("resources", "second.proj")))) { 1719 sw.Write (second); 1720 } 1721 1722 project.LoadXml (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" > 1723 <Target Name=""boo""> 1724 <Message Text=""Executing boo target""/> 1725 </Target> 1726 <Target Name=""pre""> 1727 <Message Text=""Executing pre target""/> 1728 </Target> 1729 <Import Project='Test/resources/second.proj'/> 1730 </Project>"); 1731 1732 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = 1733 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); 1734 engine.RegisterLogger (logger); 1735 1736 try { 1737 Assert.IsTrue (project.Build (), "Build failed"); 1738 1739 logger.CheckLoggedMessageHead ("Executing Second::One target", "A1"); 1740 logger.CheckLoggedMessageHead ("Executing Second::Two target", "A2"); 1741 Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found"); 1742 1743 Assert.AreEqual ("One; Two", project.DefaultTargets, "Default targets"); 1744 } catch { 1745 logger.DumpMessages (); 1746 throw; 1747 } 1748 } 1749 1750 [Test] TestNoDefaultTargets()1751 public void TestNoDefaultTargets () { 1752 Engine engine = new Engine (Consts.BinPath); 1753 Project project = engine.CreateNewProject (); 1754 1755 project.LoadXml (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" > 1756 <Target Name=""boo""> 1757 <Message Text=""Executing boo target""/> 1758 </Target> 1759 <Target Name=""pre""> 1760 <Message Text=""Executing pre target""/> 1761 </Target> 1762 </Project>"); 1763 1764 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = 1765 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); 1766 engine.RegisterLogger (logger); 1767 1768 try { 1769 Assert.IsTrue (project.Build (), "Build failed"); 1770 1771 logger.CheckLoggedMessageHead ("Executing boo target", "A1"); 1772 Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found"); 1773 1774 Assert.AreEqual ("", project.DefaultTargets, "Default targets"); 1775 } catch { 1776 logger.DumpMessages (); 1777 throw; 1778 } 1779 } 1780 1781 [Test] TestPropertiesFromImportedProjects()1782 public void TestPropertiesFromImportedProjects () 1783 { 1784 Engine engine = new Engine (Consts.BinPath); 1785 Project project = engine.CreateNewProject (); 1786 1787 string second = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" " + Consts.ToolsVersionString + @"> 1788 <PropertyGroup> 1789 <Prop1>InitialVal</Prop1> 1790 </PropertyGroup> 1791 <ItemGroup> 1792 <Second Include=""$(ThirdProp):Third""/> 1793 </ItemGroup> 1794 1795 <Target Name=""Main""> 1796 <Message Text=""Prop1: $(Prop1) FooItem: @(FooItem)""/> 1797 <Message Text=""Second: @(Second) ThirdProp: $(ThirdProp)""/> 1798 </Target> 1799 <Import Project=""third.proj""/> 1800 </Project>"; 1801 using (StreamWriter sw = new StreamWriter (Path.Combine ("Test", Path.Combine ("resources", "second.proj")))) { 1802 sw.Write (second); 1803 } 1804 1805 string third = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" " + Consts.ToolsVersionString + @"> 1806 <PropertyGroup> 1807 <ThirdProp>Third Value</ThirdProp> 1808 </PropertyGroup> 1809 </Project>"; 1810 using (StreamWriter sw = new StreamWriter (Path.Combine ("Test", Path.Combine ("resources", "third.proj")))) { 1811 sw.Write (third); 1812 } 1813 1814 project.LoadXml (@"<Project InitialTargets=""Main"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> 1815 <ItemGroup> 1816 <FooItem Include=""$(Prop1):Something""/> 1817 </ItemGroup> 1818 1819 <Import Project=""Test/resources/second.proj""/> 1820 </Project>"); 1821 1822 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = 1823 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); 1824 engine.RegisterLogger (logger); 1825 1826 try { 1827 Assert.IsTrue (project.Build (), "Build failed"); 1828 1829 logger.CheckLoggedMessageHead ("Prop1: InitialVal FooItem: InitialVal:Something", "A1"); 1830 logger.CheckLoggedMessageHead ("Second: Third Value:Third ThirdProp: Third Value", "A2"); 1831 1832 Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found"); 1833 } catch { 1834 logger.DumpMessages (); 1835 throw; 1836 } 1837 } 1838 1839 [Test] 1840 [Category ("NotDotNet")] TestMSBuildThisProperties()1841 public void TestMSBuildThisProperties () 1842 { 1843 Engine engine = new Engine (Consts.BinPath); 1844 Project project = engine.CreateNewProject (); 1845 1846 string base_dir = Path.GetFullPath (Path.Combine ("Test", "resources")) + Path.DirectorySeparatorChar; 1847 string tmp_dir = Path.GetFullPath (Path.Combine (base_dir, "tmp")) + Path.DirectorySeparatorChar; 1848 1849 string first_project = Path.Combine (base_dir, "first.proj"); 1850 string second_project = Path.Combine (tmp_dir, "second.proj"); 1851 string third_project = Path.Combine (tmp_dir, "third.proj"); 1852 1853 string first = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" " + Consts.ToolsVersionString + @"> 1854 <PropertyGroup> 1855 <FooInMain>$(MSBuildThisFileDirectory)</FooInMain> 1856 </PropertyGroup> 1857 <ItemGroup> 1858 <ItemInMain Include=""$(MSBuildThisFileFullPath)"" /> 1859 </ItemGroup> 1860 <Import Project=""tmp\second.proj""/> 1861 </Project>"; 1862 1863 string second = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" " + Consts.ToolsVersionString + @"> 1864 <PropertyGroup> 1865 <FooInImport1>$(MSBuildThisFileDirectory)</FooInImport1> 1866 </PropertyGroup> 1867 <PropertyGroup> 1868 <FooInImport2>$(MSBuildThisFileDirectory)</FooInImport2> 1869 </PropertyGroup> 1870 <ItemGroup> 1871 <ItemInImport1 Include=""$(MSBuildThisFileFullPath)"" /> 1872 </ItemGroup> 1873 1874 <Import Project=""third.proj""/> 1875 </Project>"; 1876 1877 string third = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" " + Consts.ToolsVersionString + @"> 1878 <PropertyGroup> 1879 <FooInTwo>$(MSBuildThisFileFullPath)</FooInTwo> 1880 </PropertyGroup> 1881 <ItemGroup> 1882 <ItemInTwo Include=""$(MSBuildThisFileFullPath)"" /> 1883 </ItemGroup> 1884 1885 <Target Name=""TargetInTwo""> 1886 <Message Text=""FooInMain: $(FooInMain)""/> 1887 <Message Text=""FooInImport1: $(FooInImport1)""/> 1888 <Message Text=""FooInImport2: $(FooInImport2)""/> 1889 <Message Text=""FooInTwo: $(FooInTwo)""/> 1890 1891 <Message Text=""ItemInMain: %(ItemInMain.Identity)""/> 1892 <Message Text=""ItemInImport1: %(ItemInImport1.Identity)""/> 1893 <Message Text=""ItemInTwo: %(ItemInTwo.Identity)""/> 1894 <Message Text=""Full path: $(MSBuildThisFileFullPath)""/> 1895 </Target> 1896 </Project>"; 1897 1898 File.WriteAllText (first_project, first); 1899 1900 Directory.CreateDirectory (Path.Combine (base_dir, "tmp")); 1901 File.WriteAllText (second_project, second); 1902 File.WriteAllText (third_project, third); 1903 1904 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = 1905 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); 1906 engine.RegisterLogger (logger); 1907 1908 project.Load (first_project); 1909 try { 1910 Assert.IsTrue (project.Build (), "Build failed"); 1911 1912 logger.CheckLoggedMessageHead ("FooInMain: " + base_dir, "A1"); 1913 logger.CheckLoggedMessageHead ("FooInImport1: " + tmp_dir, "A2"); 1914 logger.CheckLoggedMessageHead ("FooInImport2: " + tmp_dir, "A3"); 1915 logger.CheckLoggedMessageHead ("FooInTwo: " + third_project, "A4"); 1916 logger.CheckLoggedMessageHead ("ItemInMain: " + first_project, "A5"); 1917 logger.CheckLoggedMessageHead ("ItemInImport1: " + second_project, "A6"); 1918 logger.CheckLoggedMessageHead ("ItemInTwo: " + third_project, "A7"); 1919 logger.CheckLoggedMessageHead ("Full path: " + third_project, "A8"); 1920 1921 Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found"); 1922 } catch { 1923 logger.DumpMessages (); 1924 throw; 1925 } finally { 1926 File.Delete (first_project); 1927 File.Delete (second_project); 1928 File.Delete (third_project); 1929 } 1930 } 1931 1932 [Test] TestRequiredTask_String1()1933 public void TestRequiredTask_String1 () 1934 { 1935 CheckProjectForRequiredTests ("RequiredTestTask_String", "@(NonExistant)", 1936 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_String", null); 1937 } 1938 1939 [Test] TestRequiredTask_String2()1940 public void TestRequiredTask_String2 () 1941 { 1942 CheckProjectForRequiredTests ("RequiredTestTask_String", "$(NonExistant)", 1943 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_String", null); 1944 } 1945 1946 [Test] TestRequiredTask_Strings1()1947 public void TestRequiredTask_Strings1 () { 1948 CheckProjectForRequiredTests ("RequiredTestTask_Strings", "@(NonExistant)", 1949 true, "Build failed", "0"); 1950 } 1951 1952 [Test] TestRequiredTask_Strings2()1953 public void TestRequiredTask_Strings2 () { 1954 CheckProjectForRequiredTests ("RequiredTestTask_Strings", "$(NonExistant)", 1955 true, "Build failed", "0"); 1956 } 1957 1958 [Test] TestRequiredTask_Strings3()1959 public void TestRequiredTask_Strings3 () { 1960 CheckProjectForRequiredTests ("RequiredTestTask_Strings", "%(NonExistant.Md)", 1961 true, "Build failed", "0"); 1962 } 1963 1964 [Test] TestRequiredTask_Strings4()1965 public void TestRequiredTask_Strings4 () { 1966 CheckProjectForRequiredTests ("RequiredTestTask_Strings", " %(NonExistant.Md)", 1967 true, "Build failed", "0"); 1968 } 1969 1970 [Test] TestRequiredTask_Ints1()1971 public void TestRequiredTask_Ints1 () { 1972 CheckProjectForRequiredTests ("RequiredTestTask_IntArray", "@(NonExistant)", 1973 true, "Build failed", "count: 0"); 1974 } 1975 1976 [Test] TestRequiredTask_Ints2()1977 public void TestRequiredTask_Ints2 () { 1978 CheckProjectForRequiredTests ("RequiredTestTask_IntArray", "$(NonExistant)", 1979 true, "Build failed", "count: 0"); 1980 } 1981 1982 [Test] TestRequiredTask_OtherObjectsArray()1983 public void TestRequiredTask_OtherObjectsArray () { 1984 CheckProjectForRequiredTests ("RequiredTestTask_OtherObjectArray", "@(NonExistant)", 1985 false, "Should've failed: ObjectArray type not supported as a property type", null); 1986 } 1987 1988 [Test] TestRequiredTask_OtherObject()1989 public void TestRequiredTask_OtherObject () { 1990 CheckProjectForRequiredTests ("RequiredTestTask_OtherObjectArray", "@(NonExistant)", 1991 false, "Should've failed: ObjectArray type not supported as a property type", null); 1992 } 1993 1994 [Test] TestRequiredTask_MyTaskItems1()1995 public void TestRequiredTask_MyTaskItems1 () { 1996 CheckProjectForRequiredTests ("RequiredTestTask_MyTaskItemArray", "@(NonExistant)", 1997 false, "Should've failed: ObjectArray type not supported as a property type", null); 1998 } 1999 2000 [Test] TestRequiredTask_TaskItem1()2001 public void TestRequiredTask_TaskItem1 () 2002 { 2003 Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItem", "@(NonExistant)", 2004 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_TaskItem", null); 2005 } 2006 2007 [Test] TestRequiredTask_TaskItem2()2008 public void TestRequiredTask_TaskItem2 () 2009 { 2010 Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItem", "$(NonExistant)", 2011 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_TaskItem", null); 2012 } 2013 2014 [Test] 2015 [Category ("NotDotNet")] TestRequiredTask_TaskItemArray1()2016 public void TestRequiredTask_TaskItemArray1 () 2017 { 2018 Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItems", "@(NonExistant)", 2019 true, "Build failed", "count: 0"); 2020 2021 BuildItemGroup group = p.GetEvaluatedItemsByName ("OutItem"); 2022 Assert.AreEqual (1, group.Count, "A2"); 2023 Assert.AreEqual ("count: 0", group [0].FinalItemSpec, "A3"); 2024 } 2025 2026 [Test] 2027 [Category ("NotDotNet")] TestRequiredTask_TaskItemArray2()2028 public void TestRequiredTask_TaskItemArray2 () 2029 { 2030 Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItems", "$(NonExistant)", 2031 true, "Build failed", "count: 0"); 2032 2033 BuildItemGroup group = p.GetEvaluatedItemsByName ("OutItem"); 2034 Assert.AreEqual (1, group.Count, "A2"); 2035 Assert.AreEqual ("count: 0", group [0].FinalItemSpec, "A3"); 2036 } 2037 2038 [Test] 2039 [Category ("NotDotNet")] TestRequiredTask_TaskItemArray3()2040 public void TestRequiredTask_TaskItemArray3 () 2041 { 2042 Project p = CheckProjectForRequiredTests ("RequiredTestTask_IntArray", "$(NonExistant)", 2043 true, "Build failed", "count: 0"); 2044 2045 BuildItemGroup group = p.GetEvaluatedItemsByName ("OutItem"); 2046 Assert.AreEqual (1, group.Count, "A2"); 2047 Assert.AreEqual ("count: 0", group [0].FinalItemSpec, "A3"); 2048 } 2049 2050 [Test] 2051 [Category ("NotDotNet")] TestRequiredTask_TaskItemArray4()2052 public void TestRequiredTask_TaskItemArray4 () { 2053 Project p = CheckProjectForRequiredTests ("RequiredTestTask_IntArray", "%(NonExistant.Md)", 2054 true, "Build failed", "count: 0"); 2055 2056 BuildItemGroup group = p.GetEvaluatedItemsByName ("OutItem"); 2057 Assert.AreEqual (1, group.Count, "A2"); 2058 Assert.AreEqual ("count: 0", group[0].FinalItemSpec, "A3"); 2059 } 2060 2061 [Test] 2062 [Category ("NotDotNet")] TestRequiredTask_TaskItemArray5()2063 public void TestRequiredTask_TaskItemArray5 () { 2064 // with extra space in prop value 2065 Project p = CheckProjectForRequiredTests ("RequiredTestTask_IntArray", " %(NonExistant.Md)", 2066 true, "Build failed", "count: 0"); 2067 2068 BuildItemGroup group = p.GetEvaluatedItemsByName ("OutItem"); 2069 Assert.AreEqual (1, group.Count, "A2"); 2070 Assert.AreEqual ("count: 0", group[0].FinalItemSpec, "A3"); 2071 } 2072 2073 2074 [Test] TestCaseSensitivityOfProjectElements()2075 public void TestCaseSensitivityOfProjectElements () 2076 { 2077 string projectXml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" " + Consts.ToolsVersionString + @"> 2078 <ItemGroup> 2079 <Abc Include=""foo""> 2080 <MetaDaTA1>md1</MetaDaTA1> 2081 <METadata2>md2</METadata2> 2082 </Abc> 2083 <Abc Include=""FOO""> 2084 <MetaDaTA1>MD1 caps</MetaDaTA1> 2085 <METadata2>MD2 caps</METadata2> 2086 </Abc> 2087 <Abc Include=""hmm""> 2088 <MetaDaTA1>Md1 CAPS</MetaDaTA1> 2089 <METadata2>MD2 CAPS</METadata2> 2090 </Abc> 2091 <Abc Include=""bar""> 2092 <MeTAdata1>md3</MeTAdata1> 2093 <Metadata2>md4</Metadata2> 2094 </Abc> 2095 </ItemGroup> 2096 <PropertyGroup><ProP1>ValueProp</ProP1></PropertyGroup> 2097 <Target Name=""Main""> 2098 <MesSAGE Text=""Full item: @(ABC)""/> 2099 <MEssaGE Text=""metadata1 :%(AbC.MetaDATA1) metadata2: %(ABC.MetaDaTa2)""/> 2100 <MEssaGE Text=""metadata2 : %(AbC.MetaDAta2)""/> 2101 <MEssaGE Text=""Abc identity: %(ABC.IDENTitY)""/> 2102 <MEssaGE Text=""prop1 : $(pROp1)""/> 2103 </Target> 2104 </Project> 2105 "; 2106 Engine engine = new Engine (Consts.BinPath); 2107 Project project = engine.CreateNewProject (); 2108 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = 2109 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); 2110 engine.RegisterLogger (logger); 2111 2112 project.LoadXml (projectXml); 2113 bool result = project.Build ("Main"); 2114 if (!result) { 2115 logger.DumpMessages (); 2116 Assert.Fail ("A1: Build failed"); 2117 } 2118 2119 logger.CheckLoggedMessageHead ("Full item: foo;FOO;hmm;bar", "#A2"); 2120 logger.CheckLoggedMessageHead ("metadata1 :md1 metadata2: md2", "#A3"); 2121 logger.CheckLoggedMessageHead ("metadata1 :MD1 caps metadata2: MD2 caps", "#A4"); 2122 logger.CheckLoggedMessageHead ("metadata1 :md3 metadata2: md4", "#A5"); 2123 logger.CheckLoggedMessageHead ("metadata2 : md2", "#A6"); 2124 logger.CheckLoggedMessageHead ("metadata2 : MD2 caps", "#A7"); 2125 logger.CheckLoggedMessageHead ("metadata2 : md4", "#A8"); 2126 logger.CheckLoggedMessageHead ("Abc identity: foo", "#A9"); 2127 logger.CheckLoggedMessageHead ("Abc identity: hmm", "#A10"); 2128 logger.CheckLoggedMessageHead ("Abc identity: bar", "#A11"); 2129 logger.CheckLoggedMessageHead ("prop1 : ValueProp", "#A12"); 2130 2131 Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found"); 2132 2133 } 2134 2135 // full solution test 2136 //[Test] TestBuildSolutionProject()2137 public void TestBuildSolutionProject () 2138 { 2139 string basepath = Path.Combine ("Test", Path.Combine ("resources", "Project01")); 2140 string [] project_dirs = new string [] { 2141 Path.Combine (basepath, "Lib4"), 2142 Path.Combine (basepath, "Lib3"), 2143 Path.Combine (basepath, "Lib2"), 2144 Path.Combine (basepath, "Lib1"), 2145 Path.Combine (basepath, "Project01") 2146 }; 2147 string debug_extn = Consts.RunningOnMono () ? ".dll.mdb" : ".pdb"; 2148 2149 // List of expected output files 2150 // Lib3 2151 string [] [] project_files = new string [5][] { 2152 new string [] { "Lib4.dll", "Lib4" + debug_extn }, 2153 new string [] { "Lib3.dll" , "Lib3" + debug_extn }, 2154 // Lib2 2155 new string [] { 2156 "Lib2.dll", "Lib2" + debug_extn, 2157 "lib2_folder/Lib2.deploy.txt", 2158 Path.Combine ("fr-CA", "Lib2.resources.dll"), 2159 Path.Combine ("fr-FR", "Lib2.resources.dll"), 2160 "Lib4.dll", "Lib4" + debug_extn 2161 }, 2162 2163 // lib1 2164 new string [] { 2165 // lib1 files 2166 "Lib1.dll", "Lib2" + debug_extn, 2167 "Lib1.deploy.txt", 2168 Path.Combine ("fr-CA", "Lib1.resources.dll"), 2169 Path.Combine ("fr-FR", "Lib1.resources.dll"), 2170 Path.Combine ("en-US", "Lib1.resources.dll"), 2171 // lib2 files 2172 "Lib2.dll", "Lib2" + debug_extn, 2173 "lib2_folder/Lib2.deploy.txt", 2174 Path.Combine ("fr-CA", "Lib2.resources.dll"), 2175 Path.Combine ("fr-FR", "Lib2.resources.dll"), 2176 // lib3 files 2177 "Lib3.dll", "Lib3" + debug_extn, 2178 "Lib4.dll", "Lib4" + debug_extn 2179 }, 2180 2181 new string [] { 2182 "Project01.exe", 2183 "Project01" + (Consts.RunningOnMono () ? ".exe.mdb" : ".pdb"), 2184 // lib1 files 2185 "Lib1.dll", "Lib1" + debug_extn, 2186 "Lib1.deploy.txt", 2187 Path.Combine ("fr-CA", "Lib1.resources.dll"), 2188 Path.Combine ("fr-FR", "Lib1.resources.dll"), 2189 Path.Combine ("en-US", "Lib1.resources.dll"), 2190 // lib2 files 2191 "Lib2.dll", "Lib2" + debug_extn, 2192 "lib2_folder/Lib2.deploy.txt", 2193 Path.Combine ("fr-CA", "Lib2.resources.dll"), 2194 Path.Combine ("fr-FR", "Lib2.resources.dll"), 2195 "Lib4.dll", "Lib4" + debug_extn, 2196 } 2197 }; 2198 2199 // Cleanup 2200 for (int i = 0; i < project_dirs.Length; i ++) { 2201 string bin_path = Path.Combine (project_dirs [i], Path.Combine ("bin", "Debug")); 2202 string obj_path = Path.Combine (project_dirs [i], Path.Combine ("obj", "Debug")); 2203 2204 DeleteAllInDir (bin_path); 2205 2206 DeleteAllInDir (obj_path); 2207 } 2208 2209 Engine engine = new Engine (Consts.BinPath); 2210 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = 2211 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); 2212 engine.RegisterLogger (logger); 2213 2214 engine.GlobalProperties = new BuildPropertyGroup (); 2215 engine.GlobalProperties.SetProperty ("TreatWarningsAsErrors", "false"); 2216 2217 Project project = engine.CreateNewProject (); 2218 project.Load (Path.Combine (basepath, "Project01.sln.proj")); 2219 2220 bool result = project.Build (); 2221 if (!result) { 2222 logger.DumpMessages (); 2223 Assert.Fail ("Build failed"); 2224 } 2225 2226 // We check only the output dir, not the 'obj' 2227 string debug = Path.Combine ("bin", "Debug"); 2228 for (int i = 0; i < project_dirs.Length; i++) { 2229 CheckFilesExistInDir (Path.Combine (project_dirs [i], debug), 2230 project_files [i]); 2231 } 2232 } 2233 2234 [Test] FileNameNotResetOnLoad()2235 public void FileNameNotResetOnLoad () 2236 { 2237 // Test for bug #14295 2238 Project p = new Project (); 2239 p.FullFileName = "foo"; 2240 p.LoadXml ("<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"/>"); 2241 Assert.AreEqual ("foo", p.FullFileName); 2242 Assert.AreEqual ("foo", p.EvaluatedProperties ["MSBuildThisFile"].Value); 2243 } 2244 DeleteAllInDir(string path)2245 void DeleteAllInDir (string path) 2246 { 2247 if (!Directory.Exists (path)) 2248 return; 2249 2250 foreach (string file in Directory.GetFiles (path)) 2251 File.Delete (file); 2252 Directory.Delete (path, true); 2253 } 2254 CheckFilesExistInDir(string dir, params string [] files)2255 void CheckFilesExistInDir (string dir, params string [] files) 2256 { 2257 foreach (string file in files) { 2258 string path = Path.Combine (dir, file); 2259 Assert.IsTrue (File.Exists (path), 2260 String.Format ("Expected to find file {0}", path)); 2261 } 2262 } 2263 CheckProjectForRequiredTests(string taskname, string property_arg, bool expected_result, string error_msg, string expected_output_msg)2264 Project CheckProjectForRequiredTests (string taskname, string property_arg, bool expected_result, string error_msg, 2265 string expected_output_msg) 2266 { 2267 string projectString = String.Format (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> 2268 <UsingTask TaskName=""{0}"" AssemblyFile=""Test/resources/TestTasks.dll"" /> 2269 <Target Name=""foo""> 2270 <{0} Property=""{1}""> 2271 <Output TaskParameter=""Output"" ItemName=""OutItem""/> 2272 </{0}> 2273 <Message Text='@(OutItem)'/> 2274 </Target> 2275 </Project>", taskname, property_arg); 2276 2277 Engine engine = new Engine (Consts.BinPath); 2278 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = 2279 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); 2280 engine.RegisterLogger (logger); 2281 Project project = engine.CreateNewProject (); 2282 project.LoadXml (projectString); 2283 try { 2284 Assert.AreEqual (expected_result, project.Build (), error_msg); 2285 if (expected_result) { 2286 logger.CheckLoggedMessageHead (expected_output_msg, "A"); 2287 Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected messages found"); 2288 } 2289 } catch { 2290 logger.DumpMessages (); 2291 } 2292 return project; 2293 } 2294 CheckBuildItem(BuildItem item, string name, string [,] metadata, string finalItemSpec, string prefix)2295 static void CheckBuildItem (BuildItem item, string name, string [,] metadata, string finalItemSpec, string prefix) 2296 { 2297 Assert.AreEqual (name, item.Name, prefix + "#1"); 2298 for (int i = 0; i < metadata.GetLength (0); i++) { 2299 string key = metadata [i, 0]; 2300 string val = metadata [i, 1]; 2301 Assert.IsTrue (item.HasMetadata (key), String.Format ("{0}#2: Expected metadata '{1}' not found", prefix, key)); 2302 Assert.AreEqual (val, item.GetMetadata (key), String.Format ("{0}#3: Value for metadata {1}", prefix, key)); 2303 Assert.AreEqual (val, item.GetEvaluatedMetadata (key), String.Format ("{0}#4: Value for evaluated metadata {1}", prefix, key)); 2304 } 2305 Assert.AreEqual (finalItemSpec, item.FinalItemSpec, prefix + "#5"); 2306 } 2307 CheckProjectBuild(Project project, string [] targetNames, bool result, string [] outputNames, string prefix)2308 void CheckProjectBuild (Project project, string [] targetNames, bool result, string [] outputNames, string prefix) 2309 { 2310 IDictionary targetOutputs = new Hashtable (); 2311 2312 Assert.AreEqual (result, project.Build (targetNames, targetOutputs), prefix + "A1"); 2313 Assert.AreEqual (outputNames.Length, targetOutputs.Keys.Count, prefix + "A2"); 2314 2315 foreach (string outputName in outputNames) { 2316 Assert.IsTrue (targetOutputs.Contains (outputName), prefix + " A3: target " + outputName); 2317 2318 object o = targetOutputs [outputName]; 2319 Assert.IsTrue (typeof (ITaskItem []).IsAssignableFrom (o.GetType ()), prefix + " A4: target " + outputName); 2320 2321 ITaskItem [] items = (ITaskItem [])o; 2322 Assert.AreEqual (0, items.Length, prefix + "A5: target " + outputName); 2323 } 2324 } 2325 CreateProjectString(bool run_separate, string [] targets, bool [] results, string prefix)2326 string CreateProjectString (bool run_separate, string [] targets, bool [] results, string prefix) 2327 { 2328 StringBuilder sb = new StringBuilder (); 2329 sb.Append (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">"); 2330 sb.AppendFormat ("<Target Name = \"{0}\"><Message Text = \"#Target {1}:{0} called\" />", "main", prefix); 2331 2332 sb.AppendFormat ("<CallTarget Targets=\""); 2333 for (int i = 0; i < targets.Length; i++) 2334 sb.AppendFormat ("{0};", targets [i]); 2335 sb.AppendFormat ("\" "); 2336 2337 if (run_separate) 2338 sb.AppendFormat (" RunEachTargetSeparately=\"true\" "); 2339 sb.AppendFormat ("/></Target>\n"); 2340 2341 for (int i = 0; i < targets.Length; i++) { 2342 sb.AppendFormat ("<Target Name = \"{0}\"><Message Text = \"#Target {1}:{0} called\" />", targets [i], prefix); 2343 if (!results [i]) 2344 sb.AppendFormat ("<Error Text = \"#Error message for target {0}:{1}\"/>", prefix, targets [i]); 2345 sb.Append ("</Target>\n"); 2346 } 2347 2348 sb.Append ("</Project>"); 2349 2350 return sb.ToString (); 2351 } 2352 CreateProjectFile(string fname, bool run_separate, string [] targets, bool [] results, string prefix)2353 void CreateProjectFile (string fname, bool run_separate, string [] targets, bool [] results, string prefix) 2354 { 2355 using (StreamWriter sw = new StreamWriter (fname)) 2356 sw.Write (CreateProjectString (run_separate, targets, results, prefix)); 2357 } 2358 CreateAndLoadProject(string fname, bool run_separate, string [] targets, bool [] results, string prefix)2359 Project CreateAndLoadProject (string fname, bool run_separate, string [] targets, bool [] results, string prefix) 2360 { 2361 Engine engine = new Engine (Consts.BinPath); 2362 Project project = engine.CreateNewProject (); 2363 2364 string projectXml = CreateProjectString (run_separate, targets, results, prefix); 2365 if (fname == null) { 2366 project.LoadXml (projectXml); 2367 } else { 2368 using (StreamWriter sw = new StreamWriter (fname)) 2369 sw.Write (projectXml); 2370 project.Load (fname); 2371 File.Delete (fname); 2372 } 2373 2374 return project; 2375 } 2376 2377 [Test] CheckCommaInQuotes()2378 public void CheckCommaInQuotes () 2379 { 2380 string testString = "Test.string.with.Commas"; 2381 string documentString = string.Format (@" 2382 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> 2383 <PropertyGroup> 2384 <TestString>{0}</TestString> 2385 <TestString2>$(TestString.Replace(".",","))</TestString2> 2386 </PropertyGroup> 2387 </Project>", testString); 2388 2389 Project project = new Project (); 2390 project.LoadXml (documentString); 2391 2392 string result = project.EvaluatedProperties ["TestString2"].FinalValue; 2393 Assert.AreEqual (testString.Replace (".", ","), result, "A1"); 2394 } 2395 } 2396 } 2397