Skip to content

Commit bb0e5e6

Browse files
committed
add support for generating and including README.md in nuget package
1 parent 51ca5c3 commit bb0e5e6

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

src/Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks/Directory.Build.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ SPDX-License-Identifier: MIT
66
<ImportGroup>
77
<Import Project="$(MSBuildThisFileDirectory)..\Directory.Build.targets" />
88
<Import Project="$(MSBuildThisFileDirectory)UsingExportedTasks.targets" />
9+
<Import Project="$(MSBuildThisFileDirectory)ReadmeFile.targets" />
910
</ImportGroup>
1011
</Project>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2022 smdn <smdn@smdn.jp>
3+
SPDX-License-Identifier: MIT
4+
-->
5+
<Project>
6+
<PropertyGroup>
7+
<PackageReadmeFile>README.md</PackageReadmeFile>
8+
<NupkgReadmeFileOutputPath>$(OutputPath)$(PackageReadmeFile)</NupkgReadmeFileOutputPath>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<None Include="$(NupkgReadmeFileOutputPath)" Pack="true" PackagePath="$(PackageReadmeFile)" />
13+
</ItemGroup>
14+
15+
<!-- overrides the target GenerateNupkgReadmeFile from Smdn.MSBuild.ProjectAssets.Library -->
16+
<Target
17+
Name="GenerateNupkgReadmeFile"
18+
BeforeTargets="GenerateNuspec"
19+
>
20+
<ItemGroup>
21+
<CoreAssemblyOutputs Include="$(OutputPath)**\Smdn*.dll"/>
22+
</ItemGroup>
23+
24+
<GetCoreAssemblyInformationsFromLoadedAssembly AssemblyNames="%(CoreAssemblyOutputs.Filename)" Condition="'$(UseExportedTasksFromOutputAssembly)' == 'true'">
25+
<Output TaskParameter="AssemblyInformations" ItemName="CoreAssemblyInformations" />
26+
</GetCoreAssemblyInformationsFromLoadedAssembly>
27+
28+
<ItemGroup>
29+
<_NupkgReadmeLines Include="# $(AssemblyName)" />
30+
<_NupkgReadmeLines Include="$(Description)" />
31+
<_NupkgReadmeLines Include="## Included tasks" />
32+
<_NupkgReadmeLines Include="This package contains the following MSBuild tasks." />
33+
<_NupkgReadmeLines Include="- `%(ExportTaskNames.Identity)`" />
34+
<_NupkgReadmeLines Include="## Included assemblies" />
35+
<_NupkgReadmeLines Include="This package contains the following assemblies." />
36+
<_NupkgReadmeLines Include="- %(CoreAssemblyInformations.Identity) %(CoreAssemblyInformations.InformationalVersion)" />
37+
</ItemGroup>
38+
39+
<WriteLinesToFile
40+
File="$(NupkgReadmeFileOutputPath)"
41+
Lines="@(_NupkgReadmeLines)"
42+
Overwrite="true"
43+
/>
44+
</Target>
45+
46+
<UsingTask
47+
TaskName="GetCoreAssemblyInformationsFromLoadedAssembly"
48+
TaskFactory="RoslynCodeTaskFactory"
49+
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"
50+
>
51+
<ParameterGroup>
52+
<AssemblyNames ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
53+
<AssemblyInformations ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" />
54+
</ParameterGroup>
55+
<Task>
56+
<Using Namespace="System" />
57+
<Using Namespace="System.Linq" />
58+
<Using Namespace="System.Reflection" />
59+
<Using Namespace="System.Runtime.Versioning" />
60+
<Code Type="Fragment" Language="cs"><![CDATA[
61+
AssemblyInformations = AssemblyNames
62+
.Select(item =>
63+
AppDomain
64+
.CurrentDomain
65+
.GetAssemblies()
66+
.First(assm => assm.GetName().Name == item.ItemSpec)
67+
)
68+
.Select(static assm =>
69+
(
70+
Name: assm.GetName().Name,
71+
InformationalVersion: assm.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion,
72+
TargetFramework: assm.GetCustomAttribute<TargetFrameworkAttribute>().FrameworkName
73+
)
74+
)
75+
.Distinct()
76+
.OrderBy(static info => info.Name)
77+
.Select(static info =>
78+
new TaskItem(
79+
info.Name,
80+
new Dictionary<string, string>() {
81+
{ nameof(info.InformationalVersion), info.InformationalVersion },
82+
{ nameof(info.TargetFramework), info.TargetFramework }
83+
}
84+
)
85+
)
86+
.ToArray();
87+
]]></Code>
88+
</Task>
89+
</UsingTask>
90+
</Project>

src/Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks/Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ SPDX-License-Identifier: MIT
1010
<VersionSuffix></VersionSuffix>
1111
<Nullable>enable</Nullable>
1212
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
13+
14+
<!-- suppress generating README.md by Smdn.MSBuild.ProjectAssets.Library -->
1315
<GeneratePackageReadmeFile>false</GeneratePackageReadmeFile>
1416
</PropertyGroup>
1517

0 commit comments

Comments
 (0)