Skip to content

Commit ca9e394

Browse files
authored
Skip adding metadata if value is null (#9)
1 parent 6bd7f01 commit ca9e394

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ artifacts:
1414
- path: '**\*.nupkg'
1515
name: NuGet Packages
1616
on_failure:
17-
- ps: Get-ChildItem .\*.log -Recursive | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
17+
- ps: Get-ChildItem .\*log -Recurse | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }

src/MSBuildProjectCreator.UnitTests/ItemTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,29 @@ public void ItemIncludeNotAddedIfNull()
131131
StringCompareShould.IgnoreLineEndings);
132132
}
133133

134+
[Fact]
135+
public void MetadataNotAddedIfNull()
136+
{
137+
ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
138+
.ItemInclude(
139+
itemType: "DB5003A476FA461EB0452DDDCCE7F802",
140+
include: "303F33834A6843EDB44DB8D3186E97E0",
141+
metadata: new Dictionary<string, string>
142+
{
143+
{ "CDBA5A760C9C45CFB2E9532D4B4AE2B7", "D6A68EA723C848E19D2E17C09F7F2532" },
144+
{ "FDD9C6C5582B404188CD8C938DB2CDD9", null }
145+
})
146+
.Xml.ShouldBe(
147+
@"<Project>
148+
<ItemGroup>
149+
<DB5003A476FA461EB0452DDDCCE7F802 Include=""303F33834A6843EDB44DB8D3186E97E0"">
150+
<CDBA5A760C9C45CFB2E9532D4B4AE2B7>D6A68EA723C848E19D2E17C09F7F2532</CDBA5A760C9C45CFB2E9532D4B4AE2B7>
151+
</DB5003A476FA461EB0452DDDCCE7F802>
152+
</ItemGroup>
153+
</Project>",
154+
StringCompareShould.IgnoreLineEndings);
155+
}
156+
134157
[Fact]
135158
public void NoneItem()
136159
{

src/MSBuildProjectCreator/ProjectCreator.Items.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.Build.Construction;
66
using Microsoft.Build.Evaluation;
77
using System.Collections.Generic;
8+
using System.Linq;
89

910
namespace Microsoft.Build.Utilities.ProjectCreation
1011
{
@@ -291,7 +292,7 @@ private ProjectCreator Item(
291292

292293
if (metadata != null)
293294
{
294-
foreach (KeyValuePair<string, string> metadatum in metadata)
295+
foreach (KeyValuePair<string, string> metadatum in metadata.Where(i => i.Value != null))
295296
{
296297
item.AddMetadata(metadatum.Key, metadatum.Value);
297298
}

0 commit comments

Comments
 (0)