diff --git a/appveyor.yml b/appveyor.yml index b25fe00..1a1dda9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,4 +14,4 @@ artifacts: - path: '**\*.nupkg' name: NuGet Packages on_failure: -- ps: Get-ChildItem .\*.log -Recursive | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name } +- ps: Get-ChildItem .\*log -Recurse | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name } diff --git a/src/MSBuildProjectCreator.UnitTests/ItemTests.cs b/src/MSBuildProjectCreator.UnitTests/ItemTests.cs index 5477099..9088cd6 100644 --- a/src/MSBuildProjectCreator.UnitTests/ItemTests.cs +++ b/src/MSBuildProjectCreator.UnitTests/ItemTests.cs @@ -131,6 +131,29 @@ public void ItemIncludeNotAddedIfNull() StringCompareShould.IgnoreLineEndings); } + [Fact] + public void MetadataNotAddedIfNull() + { + ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None) + .ItemInclude( + itemType: "DB5003A476FA461EB0452DDDCCE7F802", + include: "303F33834A6843EDB44DB8D3186E97E0", + metadata: new Dictionary + { + { "CDBA5A760C9C45CFB2E9532D4B4AE2B7", "D6A68EA723C848E19D2E17C09F7F2532" }, + { "FDD9C6C5582B404188CD8C938DB2CDD9", null } + }) + .Xml.ShouldBe( + @" + + + D6A68EA723C848E19D2E17C09F7F2532 + + +", + StringCompareShould.IgnoreLineEndings); + } + [Fact] public void NoneItem() { diff --git a/src/MSBuildProjectCreator/ProjectCreator.Items.cs b/src/MSBuildProjectCreator/ProjectCreator.Items.cs index a93f3e4..87dab34 100644 --- a/src/MSBuildProjectCreator/ProjectCreator.Items.cs +++ b/src/MSBuildProjectCreator/ProjectCreator.Items.cs @@ -5,6 +5,7 @@ using Microsoft.Build.Construction; using Microsoft.Build.Evaluation; using System.Collections.Generic; +using System.Linq; namespace Microsoft.Build.Utilities.ProjectCreation { @@ -291,7 +292,7 @@ private ProjectCreator Item( if (metadata != null) { - foreach (KeyValuePair metadatum in metadata) + foreach (KeyValuePair metadatum in metadata.Where(i => i.Value != null)) { item.AddMetadata(metadatum.Key, metadatum.Value); }