Skip to content

Commit

Permalink
Ensure we always include the inferred readme
Browse files Browse the repository at this point in the history
Even if it's not already a None/Content item.

Fixes #213
  • Loading branch information
kzu committed Aug 11, 2022
1 parent 5a29ce4 commit 6acb523
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/NuGetizer.Tasks/NuGetizer.Inference.targets
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- The PackFolder of primary output (build, symbols, doc and satellite assemblies) set if PackBuildOutput = true -->
<PackFolder Condition="'$(PackFolder)' == ''">lib</PackFolder>

<!-- Whether to automatically include a None item named `readme.md` -->
<!-- Whether to automatically include the $(PackageReadmeFile) file (by default, `readme.md` alongside the project) -->
<PackReadme Condition="'$(PackReadme)' == ''">true</PackReadme>

<!-- Whether to include @(Content) items with CopyToOutputDirectory != '' in the package -->
Expand Down Expand Up @@ -241,7 +241,11 @@ 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'">
<InferenceCandidate Include="@(None -> WithMetadataValue('Filename', '$(PackageReadmeFilename)'))"
<_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)')" />

<InferenceCandidate Include="@(_ExistingReadme)"
PackagePath="%(Filename)%(Extension)"
Condition="'%(Extension)' == '$(PackageReadmeExtension)'" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Library
17 changes: 17 additions & 0 deletions src/NuGetizer.Tests/given_a_library_with_content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ public void linked_package_file_has_relative_package_path()
}));
}


[Fact]
public void has_inferred_readme()
{
var result = Builder.BuildScenario(nameof(given_a_library_with_content), new
{
PackageId = "ContentPackage"
});

result.AssertSuccess(output);

Assert.Contains(result.Items, item => item.Matches(new
{
PackagePath = @"readme.md",
}));
}

#region Content scenarios

[Fact]
Expand Down

0 comments on commit 6acb523

Please sign in to comment.