ale*_*_si 1 msbuild rest .net-core
我想自定义 OpenApiReference 元素目标。具体来说,我想在 OpenApiReference 元素定义的目标之前运行自定义目标。我怎样才能做到这一点?
假设以下配置:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<OpenApiReference Include="openapi.json" CodeGenerator="NSwagCSharp" Namespace="IntegrationService">
<Options>/GenerateDtoTypes:false /GenerateClientInterfaces:true</Options>
<ClassName>IntegrationServiceClient</ClassName>
</OpenApiReference>
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
查看 MS 源代码我能够解决如下要求:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<OpenApiGenerateCodeOnBuild>false</OpenApiGenerateCodeOnBuild>
<OpenApiGenerateCodeAtDesignTime>false</OpenApiGenerateCodeAtDesignTime>
</PropertyGroup>
<ItemGroup>
<OpenApiReference Include="openapi.json" CodeGenerator="NSwagCSharp" Namespace="IntegrationService">
<Options>/GenerateDtoTypes:false /GenerateClientInterfaces:true</Options>
<ClassName>IntegrationServiceClient</ClassName>
</OpenApiReference>
</ItemGroup>
<Target Name="DeleteServiceClient" >
<Message Text="------ Custom target: Removing existing generated service client for $(ProjectName)" Importance="high"/>
<Delete Files="$(ProjectDir)$(BaseIntermediateOutputPath)/openapiClient.cs" />
</Target>
<Target Name="GenerateServiceClient" DependsOnTargets="DeleteServiceClient;GenerateOpenApiCode" BeforeTargets="BeforeCompile"/>
</Project>
Run Code Online (Sandbox Code Playgroud)
参考:
https://github.com/dotnet/aspnetcore/blob/v3.1.10/src/Tools/Extensions.ApiDescription.Client/src/build/Microsoft.Extensions.ApiDescription.Client.targets https://github.com/dotnet /aspnetcore/blob/v3.1.10/src/Tools/Extensions.ApiDescription.Client/src/build/Microsoft.Extensions.ApiDescription.Client.props https://github.com/dotnet/aspnetcore/blob/v3.1.10/ src/Tools/Extensions.ApiDescription.Client/src/buildMultiTargeting/Microsoft.Extensions.ApiDescription.Client.targets
| 归档时间: |
|
| 查看次数: |
1359 次 |
| 最近记录: |