Example #1
0
        public void TestBeforeAndAfterTargets()
        {
            Engine  engine;
            Project project;

            string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0"">
			  <Target Name=""DefaultBeforeTarget1"" BeforeTargets=""Default"">
			    <Message Text=""Hello from DefaultBeforeTarget1""/>
			  </Target>

			  <Target Name=""DefaultBeforeTarget2"" BeforeTargets=""Default;Default;NonExistant"">
			    <Message Text=""Hello from DefaultBeforeTarget2""/>
			  </Target>


			  <Target Name=""DefaultAfterTarget"" AfterTargets=""Default  ; Foo"">
			    <Message Text=""Hello from DefaultAfterTarget""/>
			  </Target>

			  <Target Name=""Default"" DependsOnTargets=""DefaultDependsOn"">
			    <Message Text=""Hello from Default""/>
			  </Target>

			  <Target Name=""DefaultDependsOn"">
			    <Message Text=""Hello from DefaultDependsOn""/>
			  </Target>
			</Project>"            ;

            engine  = new Engine();
            project = engine.CreateNewProject();
            project.LoadXml(projectString);

            MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
                new MonoTests.Microsoft.Build.Tasks.TestMessageLogger();
            engine.RegisterLogger(logger);

            if (!project.Build("Default"))
            {
                logger.DumpMessages();
                Assert.Fail("Build failed");
            }

            logger.CheckLoggedMessageHead("Hello from DefaultDependsOn", "A1");
            logger.CheckLoggedMessageHead("Hello from DefaultBeforeTarget1", "A1");
            logger.CheckLoggedMessageHead("Hello from DefaultBeforeTarget2", "A1");
            logger.CheckLoggedMessageHead("Hello from Default", "A1");
            logger.CheckLoggedMessageHead("Hello from DefaultAfterTarget", "A1");

            Assert.AreEqual(0, logger.NormalMessageCount, "Unexpected messages found");

            //warnings for referencing unknown targets: NonExistant and Foo
            Assert.AreEqual(2, logger.WarningsCount, "Expected warnings not raised");
        }
        public void TestOverridingTargets()
        {
            Engine  engine;
            Project project;

            string second = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
				<Target Name='BeforeBuild'/>
				<Target Name='AfterBuild'/>
				<Target Name='Build' DependsOnTargets='BeforeBuild'>
					<Message Text='Build executing'/>
					<CallTarget Targets='AfterBuild'/>
				</Target>
		</Project>"        ;

            using (StreamWriter sw = new StreamWriter(Path.Combine("Test", Path.Combine("resources", "second.proj"))))
            {
                sw.Write(second);
            }

            string documentString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
				<Target Name='AfterBuild'>
					<Message Text='Overriding AfterBuild'/>
				</Target>

				<Import Project='Test/resources/second.proj'/>
				<Target Name='BeforeBuild'>
					<Message Text='Overriding BeforeBuild'/>
				</Target>
		</Project>"        ;

            engine  = new Engine(Consts.BinPath);
            project = engine.CreateNewProject();
            project.LoadXml(documentString);

            MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
                new MonoTests.Microsoft.Build.Tasks.TestMessageLogger();
            engine.RegisterLogger(logger);

            bool result = project.Build("Build");

            if (!result)
            {
                logger.DumpMessages();
                Assert.Fail("Build failed");
            }

            logger.CheckLoggedMessageHead("Overriding BeforeBuild", "A1");
            logger.CheckLoggedMessageHead("Build executing", "A1");

            Assert.AreEqual(0, logger.NormalMessageCount, "Unexpected extra messages found");
        }
Example #3
0
        public void TestImportWildcard()
        {
            string main_project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0"">
				<ItemGroup>
					<FooItem Include=""From main.proj""/>
				</ItemGroup>

				<Import Project=""tmp\*""/>

				<Target Name=""Build"">
					<Message Text=""FooItem: @(FooItem)""/>
				</Target>
			</Project>"            ;

            string other_project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0"">
				<ItemGroup>
					<FooItem Include=""From $(MSBuildThisFile)""/>
				</ItemGroup>
			</Project>"            ;

            Engine engine = new Engine(Consts.BinPath);

            MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
                new MonoTests.Microsoft.Build.Tasks.TestMessageLogger();
            engine.RegisterLogger(logger);

            string base_dir = Path.GetFullPath(Path.Combine("Test", "resources")) + Path.DirectorySeparatorChar;
            string tmp_dir  = Path.GetFullPath(Path.Combine(base_dir, "tmp")) + Path.DirectorySeparatorChar;

            string main_project   = Path.Combine(base_dir, "main.proj");
            string first_project  = Path.Combine(tmp_dir, "first.proj");
            string second_project = Path.Combine(tmp_dir, "second.proj");

            Directory.CreateDirectory(tmp_dir);
            File.WriteAllText(main_project, main_project_xml);
            File.WriteAllText(first_project, other_project_xml);
            File.WriteAllText(second_project, other_project_xml);

            Project project = engine.CreateNewProject();

            project.Load(main_project);
            try
            {
                Assert.IsTrue(project.Build("Build"), "Build failed");

                logger.CheckLoggedMessageHead("FooItem: From main.proj;From first.proj;From second.proj", "A1");
                Assert.AreEqual(0, logger.NormalMessageCount, "Unexpected extra messages found");
            }
            catch
            {
                logger.DumpMessages();
                throw;
            }
            finally
            {
                File.Delete(main_project);
                File.Delete(first_project);
                File.Delete(second_project);
            }
        }
Example #4
0
        void CheckLoggedMessages(MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger, string [] messages,
                                 string prefix)
        {
            try {
                for (int i = 0; i < messages.Length; i++)
                {
                    logger.CheckLoggedMessageHead(messages [i], String.Format("{0} #{1}", prefix, i));
                }
            } catch {
                logger.DumpMessages();
                throw;
            }

            Assert.AreEqual(0, logger.NormalMessageCount, "Number of remaining messages");
        }
Example #5
0
        public void TestLazyLoad2()
        {
            string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<UsingTask
						AssemblyFile='Test/resources/TestTasks.dll'
						TaskName='Another.SameTask'
					/>
					<UsingTask
						AssemblyFile='Test/resources/TestTasks.dll'
						TaskName='Other.SameTask'
					/>

					<Target Name='1'>
						<Other.SameTask>
							<Output TaskParameter='OutputString' ItemName='I0'/>
						</Other.SameTask>
						<Another.SameTask>
							<Output TaskParameter='OutputString' ItemName='I1'/>
						</Another.SameTask>
						<Message Text='I0: @(I0) I1: @(I1)'/>
					</Target>
				</Project>
			"            ;

            engine  = new Engine(Consts.BinPath);
            project = engine.CreateNewProject();
            MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
                new MonoTests.Microsoft.Build.Tasks.TestMessageLogger();
            engine.RegisterLogger(logger);

            project.LoadXml(documentString);

            if (!project.Build("1"))
            {
                logger.DumpMessages();
                Assert.Fail("Build failed");
            }

            logger.CheckLoggedMessageHead("I0: Other.SameTask I1: Another.SameTask", "A1");
        }
Example #6
0
		// test properties and item refs, with dynamic properties/items
		public void TestItems12 ()
		{
			string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
	<PropertyGroup>
		<Prop2>@(Ref1)</Prop2>
	</PropertyGroup>
	<ItemGroup>
		<Ref1 Include=""File1"" />
		<Files Include=""@(Ref1)""/>
	</ItemGroup>

	<Target Name=""1"">
		<Message Text=""Prop2: $(Prop2)""/>
		
		<Message Text=""Files: @(Files)""/>
		<CreateItem Include=""foobar"">
			<Output TaskParameter=""Include"" ItemName=""Ref1""/>
		</CreateItem>
		<Message Text=""Files: @(Files)""/>

		<Message Text=""Prop2: $(Prop2)""/>
		<CreateProperty Value=""NewValue"">
			<Output TaskParameter=""Value"" PropertyName=""Prop2""/>
		</CreateProperty>
		<Message Text=""Prop2: $(Prop2)""/>
	</Target>
</Project>
";

			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			proj.LoadXml (project_xml);
			engine.RegisterLogger (logger);

			if (!proj.Build ("1")) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			logger.DumpMessages ();
			logger.CheckLoggedMessageHead ("Prop2: File1", "A1");
			logger.CheckLoggedMessageHead ("Files: File1", "A1");
			logger.CheckLoggedMessageHead ("Files: File1", "A1");
			logger.CheckLoggedMessageHead ("Prop2: File1;foobar", "A1");
			logger.CheckLoggedMessageHead ("Prop2: NewValue", "A1");
			Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found");
		}
Example #7
0
		// Test Item/prop references in conditions
		public void TestItems11 () {
			string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
	<PropertyGroup>
		<Prop1>@(Item0)</Prop1>
	</PropertyGroup>
	<ItemGroup>
		<Item0 Include=""Foo""/>
		<Item1 Include=""@(Item0)""/>

		<CondItem Condition=""'@(Item1)' == '@(Item0)'"" Include=""Equal to item0""/>
		<CondItem Condition=""'@(Item1)' == 'Foo'"" Include=""Equal to item0's value""/>

		<CondItem1 Condition=""'$(Prop1)' == '@(Item0)'"" Include=""Equal to item0""/>
		<CondItem1 Condition=""'$(Prop1)' == 'Foo'"" Include=""Equal to item0's value""/>
	</ItemGroup>

	<Target Name=""1"">
		<Message Text = ""CondItem: %(CondItem.Identity)""/>
		<Message Text = ""CondItem1: %(CondItem1.Identity)""/>
	</Target>
</Project>
";

			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			proj.LoadXml (project_xml);
			engine.RegisterLogger (logger);

			if (!proj.Build ("1")) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			logger.CheckLoggedMessageHead ("CondItem: Equal to item0", "A1");
			logger.CheckLoggedMessageHead ("CondItem: Equal to item0's value", "A2");
			logger.CheckLoggedMessageHead ("CondItem1: Equal to item0", "A3");
			logger.CheckLoggedMessageHead ("CondItem1: Equal to item0's value", "A4");
			Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found");
		}
Example #8
0
		// test item metadata
		public void TestItems10 ()
		{
			string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
	<PropertyGroup>
		<Prop1>@(Item0)</Prop1>
		<Prop2>@(Ref1)</Prop2>
	</PropertyGroup>
	<ItemGroup>
		<Item0 Include=""Foo""/>
		<Ref1 Include=""File1"" />
		<IWithM Include=""A"">
			<Md>@(Item0)</Md>
			<Md2>$(Prop2)</Md2>
		</IWithM>
	</ItemGroup>

	<Target Name=""1"">
		<Message Text=""IWithM.md: %(IWithM.Md)""/>
		<Message Text=""IWithM.md2: %(IWithM.Md2)""/>

		<CreateItem Include=""Bar;Xyz"">
			<Output TaskParameter=""Include"" ItemName=""Item0""/>
		</CreateItem>
		
		<Message Text=""IWithM.md: %(IWithM.Md)""/>
		<Message Text=""IWithM.md2: %(IWithM.Md2)""/>
	</Target>
</Project>
";

			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			proj.LoadXml (project_xml);
			engine.RegisterLogger (logger);

			if (!proj.Build ("1")) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			logger.CheckLoggedMessageHead ("IWithM.md: Foo", "A1");
			logger.CheckLoggedMessageHead ("IWithM.md2: File1", "A2");

			logger.CheckLoggedMessageHead ("IWithM.md: Foo", "A3");
			logger.CheckLoggedMessageHead ("IWithM.md2: File1", "A4");
			Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found");
		}
Example #9
0
		public void TestInheritedMetadataFromItemRefs2 () {
			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			engine.RegisterLogger (logger);

			string documentString = @"
				<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
					<ItemGroup>
						<Item5 Include='ZZ'>
							<MD5>Val5</MD5>
						</Item5>

						<Item0 Include='D'>
							<MD0>Val0</MD0>
						</Item0>
						<Item1 Include='A;@(Item0)' >
							<MD1>Val1</MD1>
						</Item1>
						<Item2 Include=""@(Item1,'-');@(Item5)"" />
					</ItemGroup>

						<Target Name=""Main"">
		<Message Text=""Item2: %(Item2.Identity) MD0: %(Item2.MD0) MD1: %(Item2.MD1) MD5: %(Item2.MD5)""/>
	</Target>
				</Project>
			";

			proj.LoadXml (documentString);

			CheckItems (proj, "Item2", "A1", "A-D", "ZZ");

			if (!proj.Build ("Main")) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			logger.CheckLoggedMessageHead ("Item2: A-D MD0:  MD1:  MD5: ", "A4");
			logger.CheckLoggedMessageHead ("Item2: ZZ MD0:  MD1:  MD5: Val5", "A5");
			Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found");
		}
Example #10
0
		public void TestReservedMetadata ()
		{
			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			engine.RegisterLogger (logger);

			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<ItemGroup><File1 Include=""bar\foo.dll""/></ItemGroup>
					<Target Name='Main'>
						<Message Text='file1: @(File1)'/>
						<Message Text='file1: RootDir: %(File1.RootDir)'/>
						<Message Text='file1: Directory: %(File1.Directory)'/>
					</Target>
				</Project>";

			string projectdir = Path.Combine ("Test", "resources");
			File.WriteAllText (Path.Combine (projectdir, "test1.proj"), documentString);
			proj.Load (Path.Combine (projectdir, "test1.proj"));
			if (!proj.Build ("Main")) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}
			logger.DumpMessages ();

			logger.CheckLoggedMessageHead ("file1: " + Path.Combine ("bar", "foo.dll"), "A1");

			string path_root = Path.GetPathRoot (Path.GetFullPath (projectdir));
			logger.CheckLoggedMessageHead ("file1: RootDir: " + path_root, "A2");

			string fullpath = Path.GetFullPath (Path.Combine (projectdir, "bar"));
			logger.CheckLoggedMessageHead ("file1: Directory: " + fullpath.Substring (path_root.Length) + Path.DirectorySeparatorChar, "A3");

			if (logger.NormalMessageCount != 0) {
				logger.DumpMessages ();
				Assert.Fail ("Unexpected extra messages found");
			}
		}
Example #11
0
        public void TestSetMetadata5a()
        {
            Engine  engine;
            Project project;

            BuildItemGroup[] groups = new BuildItemGroup[1];

            string documentString = @"
				<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
					<PropertyGroup>
						<A>A</A>
						<C>@(D)</C>
					</PropertyGroup>
					<ItemGroup>
						<D Include='D'/>
						<C Include='$(C)'/>
						<A Include='a;b'>
							<Md>@(C)</Md>
						</A>
						<B Include='$(A)'/>
					</ItemGroup>
					<Target Name='main'>
						<Message Text=""a.md: %(A.Md)""/>
						<Message Text=""a.md: %(A.Meta)""/>
					</Target>
				</Project>
			"            ;

            engine  = new Engine(Consts.BinPath);
            project = engine.CreateNewProject();
            MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger();
            engine.RegisterLogger(logger);
            project.LoadXml(documentString);

            CheckMetadata(project, "A", "Md", new string [] { "@(C)", "@(C)" }, "G1");
            CheckEvaluatedMetadata(project, "A", "Md", new string[] { "D", "D" }, "G2");

            //@(B)
            Assert.AreEqual("A", project.GetEvaluatedItemsByName("B")[0].FinalItemSpec, "B2");

            project.ItemGroups.CopyTo(groups, 0);

            /*Broken right now:
             * CheckBuildItemGroup (groups[0], new string[] {
             *      "D", "D",
             *      "C", "$(C)",
             *      "A", "a;b",
             *      "B", "$(A)"
             * }, "H1");*/

            CheckBuildItemGroup(project.GetEvaluatedItemsByName("C"), new string[] {
                "C", "D"
            }, "H2");

            CheckBuildItemGroup(project.GetEvaluatedItemsByName("C"), new string[] {
                "C", "D"
            }, "I");

            project.GetEvaluatedItemsByName("A")[0].SetMetadata("Meta", "@(B)");

            Assert.AreEqual(5, project.EvaluatedItems.Count, "A0");
            Assert.AreEqual(2, project.GetEvaluatedItemsByName("A").Count, "A7");

            CheckMetadata(project, "A", "Meta", new string[] { "@(B)", "" }, "J");

            if (!project.Build())
            {
                logger.DumpMessages();
                Assert.Fail("Build failed");
            }

            CheckMetadata(project, "A", "Meta", new string[] { "@(B)", "" }, "K1");
            CheckEvaluatedMetadata(project, "A", "Meta", new string[] { "", "" }, "K2");

            logger.CheckLoggedMessageHead("a.md: D", "E10");
            logger.CheckLoggedMessageHead("a.md: ", "E11");
            Assert.AreEqual(0, logger.NormalMessageCount, "Unexpected messages left");
        }
Example #12
0
		public void TestImportWildcard ()
		{
			string main_project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0"">
				<ItemGroup>
					<FooItem Include=""From main.proj""/>
				</ItemGroup>

				<Import Project=""tmp\*""/>

				<Target Name=""Build"">
					<Message Text=""FooItem: @(FooItem)""/>
				</Target>
			</Project>";

			string other_project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0"">
				<ItemGroup>
					<FooItem Include=""From $(MSBuildThisFile)""/>
				</ItemGroup>
			</Project>";

			Engine engine = new Engine (Consts.BinPath);
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			engine.RegisterLogger (logger);

			string base_dir = Path.GetFullPath (Path.Combine ("Test", "resources")) + Path.DirectorySeparatorChar;
			string tmp_dir = Path.GetFullPath (Path.Combine (base_dir, "tmp")) + Path.DirectorySeparatorChar;

			string main_project = Path.Combine (base_dir, "main.proj");
			string first_project = Path.Combine (tmp_dir, "first.proj");
			string second_project = Path.Combine (tmp_dir, "second.proj");

			Directory.CreateDirectory (tmp_dir);
			File.WriteAllText (main_project, main_project_xml);
			File.WriteAllText (first_project, other_project_xml);
			File.WriteAllText (second_project, other_project_xml);

			Project project = engine.CreateNewProject ();
			project.Load (main_project);
			try {
				Assert.IsTrue (project.Build ("Build"), "Build failed");

				logger.CheckLoggedMessageHead ("FooItem: From main.proj;From first.proj;From second.proj", "A1");
				Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found");
			} catch {
				logger.DumpMessages ();
				throw;
			} finally {
				File.Delete (main_project);
				File.Delete (first_project);
				File.Delete (second_project);
			}
		}
Example #13
0
		public void TestSelfRefrentialItems ()
		{
			string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
	<PropertyGroup>
		<Prop1>@(Item1);Val</Prop1>
		<Prop2>@(Item2)</Prop2>
		<Prop3>@(Item3)</Prop3>
	</PropertyGroup>
	<ItemGroup>
		<Item1 Include=""Item1OldVal""/>
		<Item1 Include=""@(Item1);$(Prop1)""/>

		<Item2 Include=""Item2OldVal""/>
		<Item2 Include=""@(Item2->'%(Identity)');$(Prop2)""/>

		<Item3 Include=""Item3OldVal""/>
		<Item3 Include=""@(Item3, '_');$(Prop3)""/>

		<Item4 Include=""@(Item4)""/>
	</ItemGroup>

	<Target Name=""1"">
		<Message Text=""Item1: %(Item1.Identity)""/>
		<Message Text=""Item2: %(Item2.Identity)""/>
		<Message Text=""Item3: %(Item3.Identity)""/>
		<Message Text=""%(Item4.Identity)""/>
		<Message Text=""Item4: %(Item4.Identity)""/>
	</Target>
</Project>
";

			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			proj.LoadXml (project_xml);
			engine.RegisterLogger (logger);

			if (!proj.Build ("1")) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			logger.DumpMessages ();
			logger.CheckLoggedMessageHead ("Item1: Item1OldVal", "A1");
			logger.CheckLoggedMessageHead ("Item1: Val", "A2");
			logger.CheckLoggedMessageHead ("Item2: Item2OldVal", "A3");
			logger.CheckLoggedMessageHead ("Item3: Item3OldVal", "A4");
			logger.CheckLoggedMessageHead ("Item4: ", "A5");
			Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found");
		}
Example #14
0
		// test item refs in properties
		public void TestItems13 () {
			string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
	<PropertyGroup>
		<Prop1>@(Item0)</Prop1>
	</PropertyGroup>
	<ItemGroup>
		<Item0 Include=""Foo""/>
		<Item1 Include=""A\B.txt;A\C.txt;B\B.zip;B\C.zip"" />
		<Item2 Include=""@(Item1->'%(Extension)/$(Prop1)')"" />
	</ItemGroup>

	<Target Name='1'>
		<Message Text=""Item2: @(Item2)""/>
	</Target>
</Project>";

			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			proj.LoadXml (project_xml);
			engine.RegisterLogger (logger);

			if (!proj.Build ("1")) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			logger.CheckLoggedMessageHead ("Item2: .txt/@(Item0);.txt/@(Item0);.zip/@(Item0);.zip/@(Item0)", "A1");
			Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found");
		}
Example #15
0
		public void TestBeforeAndAfterTargets ()
		{
			Engine engine;
			Project project;

			string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0"">
			  <Target Name=""DefaultBeforeTarget1"" BeforeTargets=""Default"">
			    <Message Text=""Hello from DefaultBeforeTarget1""/>
			  </Target>

			  <Target Name=""DefaultBeforeTarget2"" BeforeTargets=""Default;Default;NonExistant"">
			    <Message Text=""Hello from DefaultBeforeTarget2""/>
			  </Target>


			  <Target Name=""DefaultAfterTarget"" AfterTargets=""Default  ; Foo"">
			    <Message Text=""Hello from DefaultAfterTarget""/>
			  </Target>

			  <Target Name=""Default"" DependsOnTargets=""DefaultDependsOn"">
			    <Message Text=""Hello from Default""/>
			  </Target>

			  <Target Name=""DefaultDependsOn"">
			    <Message Text=""Hello from DefaultDependsOn""/>
			  </Target>
			</Project>";

			engine = new Engine ();
			project = engine.CreateNewProject ();
			project.LoadXml (projectString);

			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			engine.RegisterLogger (logger);

			if (!project.Build ("Default")) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			logger.CheckLoggedMessageHead ("Hello from DefaultDependsOn", "A1");
			logger.CheckLoggedMessageHead ("Hello from DefaultBeforeTarget1", "A1");
			logger.CheckLoggedMessageHead ("Hello from DefaultBeforeTarget2", "A1");
			logger.CheckLoggedMessageHead ("Hello from Default", "A1");
			logger.CheckLoggedMessageHead ("Hello from DefaultAfterTarget", "A1");

			Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected messages found");

			//warnings for referencing unknown targets: NonExistant and Foo
			Assert.AreEqual (2, logger.WarningsCount, "Expected warnings not raised");
		}
Example #16
0
		public void TestOverridingTargets ()
		{
			Engine engine;
			Project project;

			string second = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
				<Target Name='BeforeBuild'/>
				<Target Name='AfterBuild'/>
				<Target Name='Build' DependsOnTargets='BeforeBuild'>
					<Message Text='Build executing'/>
					<CallTarget Targets='AfterBuild'/>
				</Target>
		</Project>";
			using (StreamWriter sw = new StreamWriter (Path.Combine ("Test", Path.Combine ("resources", "second.proj")))) {
				sw.Write (second);
			}

			string documentString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
				<Target Name='AfterBuild'>
					<Message Text='Overriding AfterBuild'/>
				</Target>

				<Import Project='Test/resources/second.proj'/>
				<Target Name='BeforeBuild'>
					<Message Text='Overriding BeforeBuild'/>
				</Target>
		</Project>";

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (documentString);

			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			engine.RegisterLogger (logger);

			bool result = project.Build ("Build");
			if (!result) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			logger.CheckLoggedMessageHead ("Overriding BeforeBuild", "A1");
			logger.CheckLoggedMessageHead ("Build executing", "A1");

			Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found");
		}
Example #17
0
		public void TestTargetOutputsIncludingMetadata ()
		{
			Engine engine;
			Project project;

			string documentString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
			<ItemGroup>
				<fruit Include=""apple""><md>a</md></fruit>
				<fruit Include=""rhubarb""><md>b</md></fruit>
				<fruit Include=""apricot""><md>c</md></fruit>
			</ItemGroup>

			<Target Name=""Main"">
				<CallTarget Targets=""foo"">
					<Output TaskParameter=""TargetOutputs"" ItemName=""AllOut""/>
				</CallTarget>

				<CallTarget Targets=""foo"">
					<Output TaskParameter=""TargetOutputs"" ItemName=""AllOut""/>
				</CallTarget>
				<Message Text=""AllOut: @(AllOut) metadata: %(AllOut.md)""/>
			</Target>

			<Target Name=""foo"" Outputs=""@(FooItem)"">
				<Message Text=""foo called""/>
				<CreateItem Include=""@(fruit)"">
					<Output TaskParameter=""Include"" ItemName=""FooItem""/>
				</CreateItem>
				<Message Text=""FooItem: @(FooItem) metadata: %(FooItem.md)""/>
			</Target>
		</Project>";

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (documentString);

			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			engine.RegisterLogger (logger);

			bool result = project.Build ("Main");
			if (!result) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			try {
				logger.CheckLoggedMessageHead ("foo called", "A1");
				logger.CheckLoggedMessageHead ("FooItem: apple metadata: a", "A2");
				logger.CheckLoggedMessageHead ("FooItem: rhubarb metadata: b", "A3");
				logger.CheckLoggedMessageHead ("FooItem: apricot metadata: c", "A4");

				logger.CheckLoggedMessageHead ("AllOut: apple;apple metadata: a", "A5");
				logger.CheckLoggedMessageHead ("AllOut: rhubarb;rhubarb metadata: b", "A6");
				logger.CheckLoggedMessageHead ("AllOut: apricot;apricot metadata: c", "A7");

				Assert.AreEqual (0, logger.NormalMessageCount, "Extra messages found");

				Assert.AreEqual (2, logger.TargetStarted, "TargetStarted count");
				Assert.AreEqual (2, logger.TargetFinished, "TargetFinished count");
				Assert.AreEqual (10, logger.TaskStarted, "TaskStarted count");
				Assert.AreEqual (10, logger.TaskFinished, "TaskFinished count");

			} catch (AssertionException) {
				logger.DumpMessages ();
				throw;
			}
		}
Example #18
0
        public void TestTargetOutputsIncludingMetadata()
        {
            Engine  engine;
            Project project;

            string documentString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
			<ItemGroup>
				<fruit Include=""apple""><md>a</md></fruit>
				<fruit Include=""rhubarb""><md>b</md></fruit>
				<fruit Include=""apricot""><md>c</md></fruit>
			</ItemGroup>

			<Target Name=""Main"">
				<CallTarget Targets=""foo"">
					<Output TaskParameter=""TargetOutputs"" ItemName=""AllOut""/>
				</CallTarget>

				<CallTarget Targets=""foo"">
					<Output TaskParameter=""TargetOutputs"" ItemName=""AllOut""/>
				</CallTarget>
				<Message Text=""AllOut: @(AllOut) metadata: %(AllOut.md)""/>
			</Target>

			<Target Name=""foo"" Outputs=""@(FooItem)"">
				<Message Text=""foo called""/>
				<CreateItem Include=""@(fruit)"">
					<Output TaskParameter=""Include"" ItemName=""FooItem""/>
				</CreateItem>
				<Message Text=""FooItem: @(FooItem) metadata: %(FooItem.md)""/>
			</Target>
		</Project>"        ;

            engine  = new Engine(Consts.BinPath);
            project = engine.CreateNewProject();
            project.LoadXml(documentString);

            MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
                new MonoTests.Microsoft.Build.Tasks.TestMessageLogger();
            engine.RegisterLogger(logger);

            bool result = project.Build("Main");

            if (!result)
            {
                logger.DumpMessages();
                Assert.Fail("Build failed");
            }

            try {
                logger.CheckLoggedMessageHead("foo called", "A1");
                logger.CheckLoggedMessageHead("FooItem: apple metadata: a", "A2");
                logger.CheckLoggedMessageHead("FooItem: rhubarb metadata: b", "A3");
                logger.CheckLoggedMessageHead("FooItem: apricot metadata: c", "A4");

                logger.CheckLoggedMessageHead("AllOut: apple;apple metadata: a", "A5");
                logger.CheckLoggedMessageHead("AllOut: rhubarb;rhubarb metadata: b", "A6");
                logger.CheckLoggedMessageHead("AllOut: apricot;apricot metadata: c", "A7");

                Assert.AreEqual(0, logger.NormalMessageCount, "Extra messages found");

                Assert.AreEqual(2, logger.TargetStarted, "TargetStarted count");
                Assert.AreEqual(2, logger.TargetFinished, "TargetFinished count");
                Assert.AreEqual(10, logger.TaskStarted, "TaskStarted count");
                Assert.AreEqual(10, logger.TaskFinished, "TaskFinished count");
            } catch (AssertionException) {
                logger.DumpMessages();
                throw;
            }
        }
Example #19
0
		public void TestMetadataFromItemReferences () {
			string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
	<ItemGroup>
		<Item1 Include=""Item1Val1;Item1Val2"">
			<Item1Md>False</Item1Md>
		</Item1>
		<Item2 Include=""Val1;Val2;@(Item1);Val3"">
			<Name>Random name</Name>
		</Item2>
		<Item3 Include=""foo;bar;@(Item2);Last""/>
	</ItemGroup>

	<Target Name=""Main"">
		<CreateItem Include=""@(Item3)"">
			<Output TaskParameter=""Include""  ItemName=""Final""/>
		</CreateItem>

		<Message Text=""Final: %(Final.Identity) Item1Md: %(Final.Item1Md) Name: %(Final.Name)""/>
	</Target>
</Project>";

			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			proj.LoadXml (project_xml);
			engine.RegisterLogger (logger);

			if (!proj.Build ("Main")) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			CheckItems (proj, "Final", "Z", "foo", "bar", "Val1", "Val2", "Item1Val1", "Item1Val2", "Val3", "Last");

			logger.CheckLoggedMessageHead ("Final: foo Item1Md:  Name: ", "A1");
			logger.CheckLoggedMessageHead ("Final: bar Item1Md:  Name: ", "A2");
			logger.CheckLoggedMessageHead ("Final: Val1 Item1Md:  Name: Random name", "A3");
			logger.CheckLoggedMessageHead ("Final: Val2 Item1Md:  Name: Random name", "A4");
			logger.CheckLoggedMessageHead ("Final: Item1Val1 Item1Md: False Name: Random name", "A5");
			logger.CheckLoggedMessageHead ("Final: Item1Val2 Item1Md: False Name: Random name", "A6");
			logger.CheckLoggedMessageHead ("Final: Val3 Item1Md:  Name: Random name", "A7");
			logger.CheckLoggedMessageHead ("Final: Last Item1Md:  Name: ", "A8");

			Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found");
		}
		public void TestLazyLoad2 ()
		{
			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<UsingTask
						AssemblyFile='Test/resources/TestTasks.dll'
						TaskName='Another.SameTask'
					/>
					<UsingTask
						AssemblyFile='Test/resources/TestTasks.dll'
						TaskName='Other.SameTask'
					/>

					<Target Name='1'>
						<Other.SameTask>
							<Output TaskParameter='OutputString' ItemName='I0'/>
						</Other.SameTask>
						<Another.SameTask>
							<Output TaskParameter='OutputString' ItemName='I1'/>
						</Another.SameTask>
						<Message Text='I0: @(I0) I1: @(I1)'/>
					</Target>
				</Project>
			";

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			engine.RegisterLogger (logger);

			project.LoadXml (documentString);

			if (!project.Build ("1")) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			logger.CheckLoggedMessageHead ("I0: Other.SameTask I1: Another.SameTask", "A1");
		}
Example #21
0
		public void TestEmptyItemsWithBatching ()
		{
			string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
			<UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
			<UsingTask TaskName='TestTask_TaskItem' AssemblyFile='Test\resources\TestTasks.dll' />
			<UsingTask TaskName='TestTask_TaskItems' AssemblyFile='Test\resources\TestTasks.dll' />
	<Target Name=""1"">
		<StringTestTask Property=""%(Item4.Identity)"">
			<Output TaskParameter=""OutputString"" PropertyName=""OutputString""/>
		</StringTestTask>
		<Message Text='output1: $(OutputString)'/>

		<StringTestTask Property=""  %(Item4.Identity)"">
			<Output TaskParameter=""OutputString"" PropertyName=""OutputString""/>
		</StringTestTask>
		<Message Text='output2: $(OutputString)'/>

		<StringTestTask Array=""%(Item4.Identity)"">
			<Output TaskParameter=""OutputString"" PropertyName=""OutputString""/>
		</StringTestTask>
		<Message Text='output3: $(OutputString)'/>

		<StringTestTask Array=""  %(Item4.Identity)"">
			<Output TaskParameter=""OutputString"" PropertyName=""OutputString""/>
		</StringTestTask>
		<Message Text='output4: $(OutputString)'/>


		<TestTask_TaskItem Property=""%(Item4.Identity)"">
			<Output TaskParameter=""Output"" PropertyName=""OutputString""/>
		</TestTask_TaskItem>
		<Message Text='output5: $(OutputString)'/>

		<TestTask_TaskItem Property=""  %(Item4.Identity)"">
			<Output TaskParameter=""Output"" PropertyName=""OutputString""/>
		</TestTask_TaskItem>
		<Message Text='output6: $(OutputString)'/>


		<TestTask_TaskItems Property=""  %(Item4.Identity)"">
			<Output TaskParameter=""Output"" PropertyName=""OutputString""/>
		</TestTask_TaskItems>
		<Message Text='output7: $(OutputString)'/>
	

		<!-- no space in property -->
		<TestTask_TaskItems Property=""%(Item4.Identity)"">
			<Output TaskParameter=""Output"" PropertyName=""OutputString""/>
		</TestTask_TaskItems>
		<Message Text='output8: $(OutputString)'/>

	</Target>
</Project>
";

			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
				new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			proj.LoadXml (project_xml);
			engine.RegisterLogger (logger);

			if (!proj.Build ("1")) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			logger.DumpMessages ();
			logger.CheckLoggedMessageHead ("output1: property: null ## array: null", "A1");
			logger.CheckLoggedMessageHead ("output2: property:    ## array: null", "A2");
			logger.CheckLoggedMessageHead ("output3: property: null ## array: null", "A3");
			logger.CheckLoggedMessageHead ("output4: property: null ## array: null", "A4");

			logger.CheckLoggedMessageHead ("output5: null", "A5");
			logger.CheckLoggedMessageHead ("output6: null", "A6");
			logger.CheckLoggedMessageHead ("output7: null", "A7");
			logger.CheckLoggedMessageHead ("output8: null", "A8");

			Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found");
		}
Example #22
0
		public void TestSetMetadata5a () {
			Engine engine;
			Project project;
			BuildItemGroup[] groups = new BuildItemGroup[1];

			string documentString = @"
				<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
					<PropertyGroup>
						<A>A</A>
						<C>@(D)</C>
					</PropertyGroup>
					<ItemGroup>
						<D Include='D'/>
						<C Include='$(C)'/>
						<A Include='a;b'>
							<Md>@(C)</Md>
						</A>
						<B Include='$(A)'/>
					</ItemGroup>
					<Target Name='main'>
						<Message Text=""a.md: %(A.Md)""/>
						<Message Text=""a.md: %(A.Meta)""/>
					</Target>
				</Project>
			";

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
			engine.RegisterLogger (logger);
			project.LoadXml (documentString);

			CheckMetadata (project, "A", "Md", new string [] {"@(C)", "@(C)"}, "G1");
			CheckEvaluatedMetadata (project, "A", "Md", new string[] { "D", "D" }, "G2");

			//@(B)
			Assert.AreEqual ("A", project.GetEvaluatedItemsByName ("B")[0].FinalItemSpec, "B2");

			project.ItemGroups.CopyTo (groups, 0);
			/*Broken right now:
			  CheckBuildItemGroup (groups[0], new string[] {
				"D", "D",
				"C", "$(C)",
				"A", "a;b",
				"B", "$(A)"
			}, "H1");*/

			CheckBuildItemGroup (project.GetEvaluatedItemsByName ("C"), new string[] {
				"C", "D"
			}, "H2");

			CheckBuildItemGroup (project.GetEvaluatedItemsByName ("C"), new string[] {
				"C", "D"
			}, "I");

			project.GetEvaluatedItemsByName ("A")[0].SetMetadata ("Meta", "@(B)");

			Assert.AreEqual (5, project.EvaluatedItems.Count, "A0");
			Assert.AreEqual (2, project.GetEvaluatedItemsByName ("A").Count, "A7");

			CheckMetadata (project, "A", "Meta", new string[] { "@(B)", "" }, "J");

			if (!project.Build ()) {
				logger.DumpMessages ();
				Assert.Fail ("Build failed");
			}

			CheckMetadata (project, "A", "Meta", new string[] { "@(B)", "" }, "K1");
			CheckEvaluatedMetadata (project, "A", "Meta", new string[] { "", "" }, "K2");

			logger.CheckLoggedMessageHead ("a.md: D", "E10");
			logger.CheckLoggedMessageHead ("a.md: ", "E11");
			Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected messages left");
		}