Skip to content

Commit 4203b06

Browse files
authored
Fix temporary build errors when kiota source files are added/removed (#1588)
1 parent 6ddd7b8 commit 4203b06

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

docs/usage/openapi-client.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,24 @@ The available command-line switches for Kiota are described [here](https://learn
226226

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

231231
```xml
232-
<Target Name="KiotaRunTool" BeforeTargets="BeforeCompile;CoreCompile" Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
232+
<Target Name="RemoveKiotaGeneratedCode" BeforeTargets="BeforeCompile;CoreCompile" Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
233+
<ItemGroup>
234+
<Compile Remove="**\GeneratedCode\**\*.cs" />
235+
</ItemGroup>
236+
</Target>
237+
238+
<Target Name="KiotaRunTool" BeforeTargets="BeforeCompile;CoreCompile" AfterTargets="RemoveKiotaGeneratedCode"
239+
Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
233240
<Exec
234-
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" />
241+
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" />
242+
</Target>
235243

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

src/Examples/OpenApiKiotaClientExample/OpenApiKiotaClientExample.csproj

+11-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@
2020
<PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="$(KiotaVersion)" />
2121
</ItemGroup>
2222

23-
<Target Name="KiotaRunTool" BeforeTargets="BeforeCompile;CoreCompile" Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
23+
<Target Name="RemoveKiotaGeneratedCode" BeforeTargets="BeforeCompile;CoreCompile" Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
24+
<ItemGroup>
25+
<Compile Remove="**\GeneratedCode\**\*.cs" />
26+
</ItemGroup>
27+
</Target>
28+
29+
<Target Name="KiotaRunTool" BeforeTargets="BeforeCompile;CoreCompile" AfterTargets="RemoveKiotaGeneratedCode"
30+
Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
2431
<!--
2532
Created from sources:
2633
- https://github.com/microsoft/kiota/issues/3005#issuecomment-1657806848
@@ -30,10 +37,11 @@
3037
-->
3138
<Exec
3239
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" />
40+
</Target>
3341

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

0 commit comments

Comments
 (0)