5 using Microsoft.Build.Construction;
6 using Microsoft.Build.Evaluation;
8 using Microsoft.Build.Exceptions;
9 using Microsoft.Build.Framework;
11 namespace MonoTests.Microsoft.Build.Evaluation
14 public class ResolvedImportTest
17 public void SimpleImportAndSemanticValues ()
19 string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
20 <Import Project='test_imported.proj' />
22 string imported = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
28 <X Include=""included.txt"" />
31 using (var ts = File.CreateText ("test_imported.proj"))
34 var reader = XmlReader.Create (new StringReader (xml));
35 var root = ProjectRootElement.Create (reader);
36 Assert.AreEqual ("test_imported.proj", root.Imports.First ().Project, "#1");
37 var proj = new Project (root);
38 var prop = proj.GetProperty ("A");
39 Assert.IsNotNull (prop, "#2");
40 Assert.IsTrue (prop.IsImported, "#3");
41 var item = proj.GetItems ("X").FirstOrDefault ();
42 Assert.IsNotNull (item, "#4");
43 Assert.AreEqual ("included.txt", item.EvaluatedInclude, "#5");
45 File.Delete ("imported.proj");
49 string import_overrides_test_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
53 <Import Condition=""{0}"" Project='imported.proj' />
58 string import_overrides_test_imported = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
60 <C Condition='$(A)==X'>c</C>
65 <X Include=""included.txt"" />
69 void ImportAndPropertyOverrides (string label, string condition, string valueA, string valueB)
71 using (var ts = File.CreateText ("test_imported.proj"))
72 ts.Write (import_overrides_test_imported);
74 string xml = string.Format (import_overrides_test_xml, condition);
75 var reader = XmlReader.Create (new StringReader (xml));
76 var root = ProjectRootElement.Create (reader);
77 var proj = new Project (root);
78 var a = proj.GetProperty ("A");
79 Assert.IsNotNull (a, label + "#2");
80 Assert.AreEqual (valueA, a.EvaluatedValue, label + "#3");
81 var b = proj.GetProperty ("B");
82 Assert.IsNotNull (b, label + "#4");
83 Assert.AreEqual (valueB, b.EvaluatedValue, label + "#5");
84 var c = proj.GetProperty ("C");
85 Assert.IsNotNull (b, label + "#6");
86 Assert.AreEqual ("c", b.EvaluatedValue, label + "#7");
88 File.Delete ("test_imported.proj");
93 public void ImportAndPropertyOverrides ()
95 ImportAndPropertyOverrides ("[1]", "'True'", "a", "Y");
96 ImportAndPropertyOverrides ("[2]", "A=='X'", "a", "Y"); // evaluated as true
97 ImportAndPropertyOverrides ("[2]", "B=='Y'", "X", "Y"); // evaluated as false
98 ImportAndPropertyOverrides ("[2]", "B=='b'", "X", "Y"); // of course not evaluated with imported value