Skip to content

Commit 567d0fc

Browse files
committed
add examples for Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks
1 parent 0d26994 commit 567d0fc

File tree

17 files changed

+278
-0
lines changed

17 files changed

+278
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
This package provides `GenerateApiList` MSBuild task.
99

1010
## Usage
11+
See [examples](examples/Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks/) for details and more usage examples.
12+
1113
```xml
1214
<ItemGroup>
1315
<!-- Add package reference of Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks. -->
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
api-list/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace ClassLibrary;
5+
6+
public class Class1 {
7+
public void Method1(string? input, out int output) => throw new NotImplementedException();
8+
9+
#if NET6_0_OR_GREATER
10+
public IEnumerable<string> Method2() => throw new NotImplementedException();
11+
#elif NET48_OR_GREATER
12+
public IReadOnlyList<string> Method2() => throw new NotImplementedException();
13+
#endif
14+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<LangVersion>latest</LangVersion>
6+
<Nullable>enable</Nullable>
7+
<ApiListOutputBaseDirectory>$(MSBuildThisFileDirectory)api-list</ApiListOutputBaseDirectory>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<Compile Remove="$(ApiListOutputBaseDirectory)\**\*.cs" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference
16+
Include="Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks"
17+
Version="*"
18+
PrivateAssets="all"
19+
IncludeAssets="build"
20+
/>
21+
</ItemGroup>
22+
23+
<Import Project="GenerateApiListAfterBuildTask.targets" />
24+
25+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2022 smdn <smdn@smdn.jp>
3+
SPDX-License-Identifier: MIT
4+
-->
5+
<Project>
6+
7+
<Target
8+
Name="GenerateApiListOfOutputAssemblies"
9+
Condition=" '$(TargetFramework)' != '' "
10+
AfterTargets="Build"
11+
>
12+
<ItemGroup>
13+
<GenerateApiListTargetAssemblies Include="$(TargetPath)">
14+
<OutputFilePath>$(ApiListOutputBaseDirectory)\$([System.IO.Path]::GetFileNameWithoutExtension('$(TargetPath)'))-$(TargetFramework).apilist.cs</OutputFilePath>
15+
</GenerateApiListTargetAssemblies>
16+
</ItemGroup>
17+
18+
<GenerateApiList
19+
Assemblies="@(GenerateApiListTargetAssemblies)"
20+
GenerateLanguagePrimitiveType="true"
21+
GenerateNullableAnnotations="true"
22+
>
23+
<Output TaskParameter="GeneratedFiles" ItemName="GeneratedApiListFiles" />
24+
</GenerateApiList>
25+
26+
<Message Text="Generated API list '%(GeneratedApiListFiles.Identity)' from '%(GeneratedApiListFiles.SourceAssembly)'" Importance="high" />
27+
</Target>
28+
29+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This directory demonstrates generating an API list after building a single targeting project.
2+
3+
# Steps to run this example
4+
1. Run `dotnet restore`
5+
2. Run `dotnet build`, and the API list will be generated to the directory `api-list`.
6+
7+
You can configure the directory where the API listings will be generated by specifying `ApiListOutputBaseDirectory` project property.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace ClassLibrary;
5+
6+
public class Class1 {
7+
public void Method1(string? input, out int output) => throw new NotImplementedException();
8+
9+
#if NET6_0_OR_GREATER
10+
public IEnumerable<string> Method2() => throw new NotImplementedException();
11+
#elif NET48_OR_GREATER
12+
public IReadOnlyList<string> Method2() => throw new NotImplementedException();
13+
#endif
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net6.0;net48;netstandard2.1</TargetFrameworks>
5+
<LangVersion>latest</LangVersion>
6+
<Nullable>enable</Nullable>
7+
<ApiListOutputBaseDirectory>$(MSBuildThisFileDirectory)api-list</ApiListOutputBaseDirectory>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<Compile Remove="$(ApiListOutputBaseDirectory)\**\*.cs" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference
16+
Include="Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks"
17+
Version="*"
18+
PrivateAssets="all"
19+
IncludeAssets="build"
20+
/>
21+
</ItemGroup>
22+
23+
<Import Project="GenerateApiListAfterBuildTaskMultitargeting.targets" />
24+
25+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2022 smdn <smdn@smdn.jp>
3+
SPDX-License-Identifier: MIT
4+
-->
5+
<Project>
6+
7+
<Target
8+
Name="GenerateApiListOfOutputAssembliesMultitargeting"
9+
Condition=" '$(TargetFramework)' == '' "
10+
AfterTargets="DispatchToInnerBuilds"
11+
>
12+
<ItemGroup>
13+
<GenerateApiListTargetAssemblies Include="%(InnerOutput.Identity)">
14+
<OutputFilePath>$(ApiListOutputBaseDirectory)\%(InnerOutput.Filename)-%(InnerOutput.TargetFrameworkIdentifier)-v%(InnerOutput.TargetFrameworkVersion).apilist.cs</OutputFilePath>
15+
</GenerateApiListTargetAssemblies>
16+
</ItemGroup>
17+
18+
<GenerateApiList
19+
Assemblies="@(GenerateApiListTargetAssemblies)"
20+
GenerateLanguagePrimitiveType="true"
21+
GenerateNullableAnnotations="true"
22+
>
23+
<Output TaskParameter="GeneratedFiles" ItemName="GeneratedApiListFiles" />
24+
</GenerateApiList>
25+
26+
<Message Text="Generated API list '%(GeneratedApiListFiles.Identity)' from '%(GeneratedApiListFiles.SourceAssembly)'" Importance="high" />
27+
</Target>
28+
29+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This directory demonstrates generating API lists after building a multi-targeting project.
2+
3+
# Steps to run this example
4+
1. Run `dotnet restore`
5+
2. Run `dotnet build`, and the API list will be generated to the directory `api-list`.
6+
7+
You can configure the directory where the API listings will be generated by specifying `ApiListOutputBaseDirectory` project property.

0 commit comments

Comments
 (0)