Skip to content

Don't fail for multiple readme files in content #446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/NuGetizer.Tasks/NuGetizer.Inference.targets
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ Copyright (c) .NET Foundation. All rights reserved.

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

<InferenceCandidate Include="@(_ExistingReadme -> Distinct())"
PackagePath="%(Filename)%(Extension)"
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetizer.Tests/NuGetizer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<DefaultItemExcludes>$(DefaultItemExcludes);Scenarios\**\*</DefaultItemExcludes>
<LangVersion>Latest</LangVersion>
<LangVersion>Preview</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
31 changes: 31 additions & 0 deletions src/NuGetizer.Tests/given_a_packaging_project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,37 @@ public void when_readme_found_then_adds_metadata_and_content()
}));
}

[Fact]
public void when_multiple_readmes_found_then_adds_metadata_and_content_for_root()
{
var result = Builder.BuildProject(@"
<Project Sdk='Microsoft.Build.NoTargets/3.7.0'>
<PropertyGroup>
<PackageId>Packer</PackageId>
<TargetFramework>net6.0</TargetFramework>
<!-- Only needed since for scenarios we set this to false. -->
<EnableDefaultItems>true</EnableDefaultItems>
</PropertyGroup>
</Project>",
"Pack,GetPackageContents", output,
files: [("readme.md", @"# readme"), ("docs/readme.md", @"# readme2")]);

result.AssertSuccess(output);

// Assert the readme file is added to the package
Assert.Contains(result.Items, item => item.Matches(new
{
PackagePath = @"readme.md",
}));

// Assert the package metadata is present too
Assert.Contains(result.Items, item => item.Matches(new
{
Identity = "Packer",
Readme = "readme.md",
}));
}

[Fact]
public void when_readme_custom_extension_specified_then_adds_metadata_and_content()
{
Expand Down