Skip to content

Fix temporary build errors when kiota source files are added/removed #1588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions docs/usage/openapi-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,24 @@ The available command-line switches for Kiota are described [here](https://learn

At the time of writing, Kiota provides [no official integration](https://github.com/microsoft/kiota/issues/3005) with MSBuild.
Our [example project](https://github.com/json-api-dotnet/JsonApiDotNetCore/tree/openapi/src/Examples/OpenApiKiotaClientExample) takes a stab at it,
although it has glitches. If you're an MSBuild expert, please help out!
which seems to work. If you're an MSBuild expert, please help out!

```xml
<Target Name="KiotaRunTool" BeforeTargets="BeforeCompile;CoreCompile" Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
<Target Name="RemoveKiotaGeneratedCode" BeforeTargets="BeforeCompile;CoreCompile" Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
<ItemGroup>
<Compile Remove="**\GeneratedCode\**\*.cs" />
</ItemGroup>
</Target>

<Target Name="KiotaRunTool" BeforeTargets="BeforeCompile;CoreCompile" AfterTargets="RemoveKiotaGeneratedCode"
Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
<Exec
Command="dotnet kiota generate --language CSharp --class-name ExampleApiClient --namespace-name OpenApiKiotaClientExample.GeneratedCode --output ./GeneratedCode --backing-store --exclude-backward-compatible --clean-output --clear-cache --openapi ..\JsonApiDotNetCoreExample\GeneratedSwagger\JsonApiDotNetCoreExample.json" />
Command="dotnet kiota generate --language CSharp --class-name ExampleApiClient --namespace-name OpenApiKiotaClientExample.GeneratedCode --output ./GeneratedCode --backing-store --exclude-backward-compatible --clean-output --clear-cache --log-level Error --openapi ../JsonApiDotNetCoreExample/GeneratedSwagger/JsonApiDotNetCoreExample.json" />
</Target>

<Target Name="IncludeKiotaGeneratedCode" BeforeTargets="BeforeCompile;CoreCompile" AfterTargets="KiotaRunTool"
Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
<ItemGroup>
<!-- This isn't entirely reliable: may require a second build after the source swagger.json has changed, to get rid of compile errors. -->
<Compile Remove="**\GeneratedCode\**\*.cs" />
<Compile Include="**\GeneratedCode\**\*.cs" />
</ItemGroup>
</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@
<PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="$(KiotaVersion)" />
</ItemGroup>

<Target Name="KiotaRunTool" BeforeTargets="BeforeCompile;CoreCompile" Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
<Target Name="RemoveKiotaGeneratedCode" BeforeTargets="BeforeCompile;CoreCompile" Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
<ItemGroup>
<Compile Remove="**\GeneratedCode\**\*.cs" />
</ItemGroup>
</Target>

<Target Name="KiotaRunTool" BeforeTargets="BeforeCompile;CoreCompile" AfterTargets="RemoveKiotaGeneratedCode"
Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
<!--
Created from sources:
- https://github.com/microsoft/kiota/issues/3005#issuecomment-1657806848
Expand All @@ -30,10 +37,11 @@
-->
<Exec
Command="dotnet kiota generate --language CSharp --class-name ExampleApiClient --namespace-name OpenApiKiotaClientExample.GeneratedCode --output ./GeneratedCode --backing-store --exclude-backward-compatible --clean-output --clear-cache --log-level Error --openapi ../JsonApiDotNetCoreExample/GeneratedSwagger/JsonApiDotNetCoreExample.json" />
</Target>

<Target Name="IncludeKiotaGeneratedCode" BeforeTargets="BeforeCompile;CoreCompile" AfterTargets="KiotaRunTool"
Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
<ItemGroup>
<!-- This isn't entirely reliable: may require a second build after the source swagger.json has changed, to get rid of compile errors. -->
<Compile Remove="**\GeneratedCode\**\*.cs" />
<Compile Include="**\GeneratedCode\**\*.cs" />
</ItemGroup>
</Target>
Expand Down
Loading