From 616efc5cd701fd4e69888e9f918658f1358aaaba Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Mon, 28 Feb 2011 00:32:50 +0530 Subject: [PATCH] [xbuild] Remove property if Output TaskParameter is null. If the TaskParameter for Output of a task is null, then remove the corresponding property. Add relevant test. --- .../Microsoft.Build.BuildEngine/TaskEngine.cs | 12 ++++-- .../CreatePropertyTest.cs | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/TaskEngine.cs b/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/TaskEngine.cs index e0ddc933326..ef9a1afdf96 100644 --- a/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/TaskEngine.cs +++ b/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/TaskEngine.cs @@ -177,10 +177,6 @@ namespace Microsoft.Build.BuildEngine { throw new InvalidProjectFileException ("This is not output property."); o = propertyInfo.GetValue (task, null); - // FIXME: maybe we should throw an exception here? - if (o == null) - continue; - if (itemName != String.Empty) { PublishItemGroup (propertyInfo, o, itemName); } else { @@ -198,6 +194,11 @@ namespace Microsoft.Build.BuildEngine { object o, string propertyName) { + if (o == null) { + parentProject.EvaluatedProperties.RemoveProperty (propertyName); + return; + } + BuildProperty bp; try { bp = ChangeType.ToBuildProperty (o, propertyInfo.PropertyType, propertyName); @@ -214,6 +215,9 @@ namespace Microsoft.Build.BuildEngine { object o, string itemName) { + if (o == null) + return; + BuildItemGroup newItems; try { newItems = ChangeType.ToBuildItemGroup (o, propertyInfo.PropertyType, itemName); diff --git a/mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreatePropertyTest.cs b/mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreatePropertyTest.cs index 8b68c7dc971..543c3fd0448 100644 --- a/mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreatePropertyTest.cs +++ b/mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreatePropertyTest.cs @@ -127,5 +127,45 @@ namespace MonoTests.Microsoft.Build.Tasks { Assert.AreEqual ("@(IG)", project.EvaluatedProperties["C"].FinalValue, "A6"); } + [Test] + public void TestEmptyPropertyValue () + { + Engine engine; + Project project; + + string documentString = @" + + + 1 + + + + + + + + + + "; + + engine = new Engine (Consts.BinPath); + + TestMessageLogger testLogger = new TestMessageLogger (); + engine.RegisterLogger (testLogger); + + project = engine.CreateNewProject (); + project.LoadXml (documentString); + if (!project.Build ("1")) { + testLogger.DumpMessages (); + Assert.Fail ("Build failed"); + } + + testLogger.CheckLoggedMessageHead ("Before: 1", "A1"); + testLogger.CheckLoggedMessageHead ("After: ", "A2"); + Assert.AreEqual (0, testLogger.NormalMessageCount, "Unexpected messages found"); + } } } -- 2.25.1