Skip to content

Commit 2171440

Browse files
committed
Don't fail for multiple readme files in content
When multiple readme files exist in package content, but with distinct relative paths within it, our package inference would fail because it would consider only the FileName when updating its Pack properties.
1 parent 6c72f66 commit 2171440

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

src/NuGetizer.Tasks/NuGetizer.Inference.targets

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ Copyright (c) .NET Foundation. All rights reserved.
286286

287287
<!-- Even if all these conditions are false, the user can still explicitly pack the file, of course -->
288288
<ItemGroup Label="Readme" Condition="'$(PackReadme)' == 'true' and '$(PackageReadmeFile)' != '' and '$(IsPackable)' == 'true'">
289-
<_ExistingReadme Include="@(None -> WithMetadataValue('Filename', '$(PackageReadmeFilename)'))" />
290-
<_ExistingReadme Include="@(Content -> WithMetadataValue('Filename', '$(PackageReadmeFilename)'))" Condition="'@(_ExistingReadme)' == ''" />
291-
<_ExistingReadme Include="$(MSBuildProjectDirectory)\$(PackageReadmeFilename)$(PackageReadmeExtension)" Condition="'@(_ExistingReadme)' == '' and Exists('$(MSBuildProjectDirectory)\$(PackageReadmeFilename)$(PackageReadmeExtension)')" />
289+
<_ExistingReadme Include="@(None -> WithMetadataValue('Identity', '$(PackageReadmeFile)'))" />
290+
<_ExistingReadme Include="@(Content -> WithMetadataValue('Identity', '$(PackageReadmeFile)'))" Condition="'@(_ExistingReadme)' == ''" />
291+
<_ExistingReadme Include="$(MSBuildProjectDirectory)\$(PackageReadmeFile)" Condition="'@(_ExistingReadme)' == '' and Exists('$(MSBuildProjectDirectory)\$(PackageReadmeFile)')" />
292292

293293
<InferenceCandidate Include="@(_ExistingReadme -> Distinct())"
294294
PackagePath="%(Filename)%(Extension)"

src/NuGetizer.Tests/NuGetizer.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>net472</TargetFramework>
55
<DefaultItemExcludes>$(DefaultItemExcludes);Scenarios\**\*</DefaultItemExcludes>
6-
<LangVersion>Latest</LangVersion>
6+
<LangVersion>Preview</LangVersion>
77
</PropertyGroup>
88

99
<ItemGroup>

src/NuGetizer.Tests/given_a_packaging_project.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,37 @@ public void when_readme_found_then_adds_metadata_and_content()
437437
}));
438438
}
439439

440+
[Fact]
441+
public void when_multiple_readmes_found_then_adds_metadata_and_content_for_root()
442+
{
443+
var result = Builder.BuildProject(@"
444+
<Project Sdk='Microsoft.Build.NoTargets/3.7.0'>
445+
<PropertyGroup>
446+
<PackageId>Packer</PackageId>
447+
<TargetFramework>net6.0</TargetFramework>
448+
<!-- Only needed since for scenarios we set this to false. -->
449+
<EnableDefaultItems>true</EnableDefaultItems>
450+
</PropertyGroup>
451+
</Project>",
452+
"Pack,GetPackageContents", output,
453+
files: [("readme.md", @"# readme"), ("docs/readme.md", @"# readme2")]);
454+
455+
result.AssertSuccess(output);
456+
457+
// Assert the readme file is added to the package
458+
Assert.Contains(result.Items, item => item.Matches(new
459+
{
460+
PackagePath = @"readme.md",
461+
}));
462+
463+
// Assert the package metadata is present too
464+
Assert.Contains(result.Items, item => item.Matches(new
465+
{
466+
Identity = "Packer",
467+
Readme = "readme.md",
468+
}));
469+
}
470+
440471
[Fact]
441472
public void when_readme_custom_extension_specified_then_adds_metadata_and_content()
442473
{

0 commit comments

Comments
 (0)