|
| 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> |
0 commit comments