[xbuild] Remove property if Output TaskParameter is null.
authorAnkit Jain <radical@corewars.org>
Sun, 27 Feb 2011 19:02:50 +0000 (00:32 +0530)
committerAnkit Jain <radical@corewars.org>
Sun, 27 Feb 2011 21:40:14 +0000 (03:10 +0530)
If the TaskParameter for Output of a task is null, then remove
the corresponding property.
Add relevant test.

mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/TaskEngine.cs
mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreatePropertyTest.cs

index e0ddc933326f20b74995ee09c666c0b8eecc7d9a..ef9a1afdf96b6bf4849bd910de64d0277beaa017 100644 (file)
@@ -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);
index 8b68c7dc9711ce5e67cae9d59ad17f59462a731e..543c3fd0448aa9f98d089d29275c16dd734622bf 100644 (file)
@@ -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 = @"
+                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+                                       <PropertyGroup>
+                                               <A>1</A>
+                                       </PropertyGroup>
+                                       <Target Name='1'>
+                                               <Message Text='Before: $(A)'/>
+                                               <CreateProperty Value=''>
+                                                       <Output
+                                                               TaskParameter='Value'
+                                                               PropertyName='A'
+                                                       />
+                                               </CreateProperty>
+                                               <Message Text='After: $(A)'/>
+                                       </Target>
+                               </Project>
+                       ";
+
+                       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");
+               }
        }
 }