Skip to content

Commit f8538b7

Browse files
Update NuGet targets
1 parent 82a5c9f commit f8538b7

File tree

1 file changed

+58
-10
lines changed

1 file changed

+58
-10
lines changed

build/nuget.targets

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,73 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33

4-
<Target Name="GenerateReleaseNotes" BeforeTargets="GenerateNuspec" Label="NuGet">
4+
<PropertyGroup>
5+
<SourcePackageReadmeFile>$(MSBuildProjectDirectory)\README.md</SourcePackageReadmeFile>
6+
<TargetPackageReadmeFile>$(BaseIntermediateOutputPath)\README.md</TargetPackageReadmeFile>
7+
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);IncludeNuGetReadme</TargetsForTfmSpecificContentInPackage>
11+
</PropertyGroup>
12+
13+
<Target Name="IncludeNuGetReadme">
14+
<ItemGroup>
15+
<TfmSpecificPackageFile Include="$(TargetPackageReadmeFile)" PackagePath="" />
16+
</ItemGroup>
17+
</Target>
18+
19+
<!--
20+
reads the lines from the 'ReleaseNotes.txt' file, if any, and transforms them into a bulleted list.
21+
if there are no specific release notes, then the corresponding release link is used. minor and
22+
patch versions will typically have release notes. major releases often have too many items to list
23+
and are better served by the official release page. the original read me file is copied to the
24+
intermediate output, the releases notes appended, and the final file is packed in the package
25+
-->
26+
<Target Name="GenerateReadme"
27+
BeforeTargets="GenerateNuspec"
28+
Condition="Exists('$(SourcePackageReadmeFile)')"
29+
Label="NuGet">
530

631
<PropertyGroup>
732
<ReleaseNotesFile>$(MSBuildProjectDirectory)\ReleaseNotes.txt</ReleaseNotesFile>
33+
<PackageReleaseNotes>https://github.com/dotnet/aspnet-api-versioning/releases/tag/v$(PackageVersion)</PackageReleaseNotes>
34+
</PropertyGroup>
35+
36+
<!-- if there is banner text, merge as one big string
37+
note: ReadLinesFromFile as items won't work here because empty lines are discarded -->
38+
<PropertyGroup Condition=" '$(ReadmeBanner)' != '' ">
39+
<ReadmeContent>| :mega: $(ReadmeBanner) |
40+
|-|
41+
42+
$([System.IO.File]::ReadAllText('$(SourcePackageReadmeFile)'))
43+
</ReadmeContent>
844
</PropertyGroup>
9-
45+
46+
<!-- write all text with the banner -->
47+
<WriteLinesToFile File="$(TargetPackageReadmeFile)"
48+
Lines="$(ReadmeContent)"
49+
Overwrite="true"
50+
Condition=" '$(ReadmeBanner)' != '' "/>
51+
52+
<!-- just copy the file without a banner -->
53+
<Copy SourceFiles="$(SourcePackageReadmeFile)"
54+
DestinationFiles="$(TargetPackageReadmeFile)"
55+
OverwriteReadOnlyFiles="true"
56+
Condition=" '$(ReadmeBanner)' == '' " />
57+
1058
<ReadLinesFromFile File="$(ReleaseNotesFile)" Condition="Exists('$(ReleaseNotesFile)')" >
1159
<Output TaskParameter="Lines" ItemName="ReleaseNotes"/>
1260
</ReadLinesFromFile>
1361

14-
<ItemGroup Condition=" @(ReleaseNotes->Count()) == 0 ">
15-
<ReleaseNotes Include="https://github.com/Microsoft/aspnet-api-versioning/releases/tag/v$(PackageVersion)" />
16-
</ItemGroup>
62+
<!-- append link to release -->
63+
<WriteLinesToFile File="$(TargetPackageReadmeFile)"
64+
Lines="$(PackageReleaseNotes)"
65+
Condition="@(ReleaseNotes->Count()) == 0" />
1766

18-
<PropertyGroup>
19-
<ReleaseNoteCount>@(ReleaseNotes->Count())</ReleaseNoteCount>
20-
<PackageReleaseNotes Condition=" $(ReleaseNoteCount) &lt; 2 " >@(ReleaseNotes->'%(Identity)')</PackageReleaseNotes>
21-
<PackageReleaseNotes Condition=" $(ReleaseNoteCount) &gt; 1 " >@(ReleaseNotes->'• %(Identity)','%0D%0A')</PackageReleaseNotes>
22-
</PropertyGroup>
67+
<!-- append specific release notes -->
68+
<WriteLinesToFile File="$(TargetPackageReadmeFile)"
69+
Lines="@(ReleaseNotes->'- %(Identity)')"
70+
Condition="@(ReleaseNotes->Count()) > 0" />
2371

2472
</Target>
2573

0 commit comments

Comments
 (0)