2 // ProjectInstanceTest.cs
5 // Atsushi Enomoto (atsushi@xamarin.com)
7 // Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
32 using Microsoft.Build.Construction;
33 using Microsoft.Build.Execution;
34 using NUnit.Framework;
35 using Microsoft.Build.Evaluation;
37 namespace MonoTests.Microsoft.Build.Execution
40 public class ProjectInstanceTest
43 public void ItemsAndProperties ()
45 string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
47 <X Condition='false' Include='bar.txt' />
54 <P Condition='false'>void</P>
55 <P Condition='true'>valid</P>
58 var xml = XmlReader.Create (new StringReader(project_xml));
59 var root = ProjectRootElement.Create (xml);
60 var proj = new ProjectInstance (root);
61 var item = proj.Items.First ();
62 Assert.AreEqual ("foo.txt", item.EvaluatedInclude, "#1");
63 var prop = proj.Properties.First (p => p.Name=="P");
64 Assert.AreEqual ("valid", prop.EvaluatedValue, "#2");
65 Assert.IsNotNull (proj.GetProperty ("MSBuildProjectDirectory"), "#3");
66 Assert.AreEqual ("2.0", proj.ToolsVersion, "#4");
70 public void ExplicitToolsVersion ()
72 string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
73 var xml = XmlReader.Create (new StringReader(project_xml));
74 var root = ProjectRootElement.Create (xml);
75 var proj = new ProjectInstance (root, null, "4.0", new ProjectCollection ());
76 Assert.AreEqual ("4.0", proj.ToolsVersion, "#1");
80 public void BuildEmptyProject ()
82 string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
83 var xml = XmlReader.Create (new StringReader (project_xml), null, "file://localhost/foo.xml");
84 var root = ProjectRootElement.Create (xml);
85 // This seems to do nothing and still returns true
86 root.FullPath = "ProjectInstanceTest.BuildEmptyProject.1.proj";
87 Assert.IsTrue (new ProjectInstance (root).Build (), "#1");
88 // This seems to fail to find the appropriate target
89 root.FullPath = "ProjectInstanceTest.BuildEmptyProject.2.proj";
90 Assert.IsFalse (new ProjectInstance (root).Build ("Build", null), "#2");
91 // Thus, this tries to build all the targets (empty) and no one failed, so returns true(!)
92 root.FullPath = "ProjectInstanceTest.BuildEmptyProject.3.proj";
93 Assert.IsTrue (new ProjectInstance (root).Build (new string [0], null), "#3");
94 // Actially null "targets" is accepted and returns true(!!)
95 root.FullPath = "ProjectInstanceTest.BuildEmptyProject.4.proj";
96 Assert.IsTrue (new ProjectInstance (root).Build ((string []) null, null), "#4");
97 // matching seems to be blindly done, null string also results in true(!!)
98 root.FullPath = "ProjectInstanceTest.BuildEmptyProject.5.proj";
99 Assert.IsTrue (new ProjectInstance (root).Build ((string) null, null), "#5");