Skip to content

Commit

Permalink
[IDP-1141] Only run OpenApi MSBuild task when there are binary changes (
Browse files Browse the repository at this point in the history
#45)

* [IDP-1141] Only run OpenApi MSBuild task when there are binary changes

* PR feedback

* PR feedback
  • Loading branch information
heqianwang authored Apr 10, 2024
1 parent 2ecc2c7 commit 4bcfdd4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/WebApiDebugger/WebApiDebugger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
<ProjectReference Include="..\Workleap.OpenApi.MSBuild\Workleap.OpenApi.MSBuild.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>

<Import Project="..\Workleap.OpenApi.MSBuild\msbuild\tools\Workleap.OpenApi.MSBuild.targets" />
<Import Project="..\Workleap.OpenApi.MSBuild\msbuild\build\Workleap.OpenApi.MSBuild.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OpenApiEnabled Condition="'$(OpenApiEnabled)' == ''">true</OpenApiEnabled>

<!-- We use this property when developing this MSBuild task in an IDE, -->
<!-- so we can reference the task assembly that is built in its bin folder instead of the one in the distributed NuGet package -->
<OpenApiDebuggingEnabled Condition="'$(OpenApiDebuggingEnabled)' == ''">false</OpenApiDebuggingEnabled>
<OpenApiDebuggingEnabled Condition="'$(OpenApiDebuggingEnabled)' == ''">false</OpenApiDebuggingEnabled>
<OpenApiTouchFileName>openapi_spec_validated.txt</OpenApiTouchFileName>
</PropertyGroup>

<!-- This is the location of this task assembly when it is distributed as a NuGet package -->
Expand All @@ -14,8 +14,16 @@
<!-- This is the location of this task assembly when debugging the task in an IDE -->
<UsingTask Condition="'$(OpenApiDebuggingEnabled)' == 'true'" TaskName="$(MSBuildThisFileName).ValidateOpenApiTask" AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\$(Configuration)\netstandard2.0\$(MSBuildThisFileName).dll" />

<!-- We can only analyze the OpenAPI spec after the project has been built -->
<Target Name="ValidateOpenApi" DependsOnTargets="ResolveProjectReferences" AfterTargets="Build" Condition="'$(OpenApiEnabled)' == 'true'">
<!-- We validate and regenerate OpenAPI specs after the build stage. This task is executed only if the compiled outputs are newer than the last task execution. -->
<!-- We decide to use compared a touched files strategy with the output of the CoreCompile target along with project files. Use Binlog to obtain target inputs/outputs -->
<Target Name="ValidateOpenApi" AfterTargets="Build"
Inputs="$(MSBuildAllProjects);
@(DocFileItem);
@(IntermediateAssembly);
@(IntermediateRefAssembly);
@(CustomAdditionalCompileOutputs)"
Outputs="$(IntermediateOutputPath)$(OpenApiTouchFileName)"
Condition="'$(OpenApiEnabled)' == 'true'">
<PropertyGroup>
<!-- Set development mode: ValidateContract or GenerateContract -->
<OpenApiDevelopmentMode Condition="'$(OpenApiDevelopmentMode)' == ''">GenerateContract</OpenApiDevelopmentMode>
Expand All @@ -26,7 +34,7 @@
<OpenApiCompareCodeAgainstSpecFile Condition="'$(OpenApiCompareCodeAgainstSpecFile)' == '' and '$(OpenApiDevelopmentMode)' == 'GenerateContract' and '$(Configuration)' == 'Release'">true</OpenApiCompareCodeAgainstSpecFile>
<OpenApiCompareCodeAgainstSpecFile Condition="'$(OpenApiCompareCodeAgainstSpecFile)' == '' and '$(OpenApiDevelopmentMode)' == 'CodeFirst' and '$(Configuration)' == 'Release'">true</OpenApiCompareCodeAgainstSpecFile>
<OpenApiCompareCodeAgainstSpecFile Condition="'$(OpenApiCompareCodeAgainstSpecFile)' == ''">false</OpenApiCompareCodeAgainstSpecFile>

<!-- The path of the ASP.NET Core project build output directory -->
<StartupAssemblyPath Condition="'$(StartupAssemblyPath)' == ''">$([System.IO.Path]::Combine($(MSBuildProjectDirectory), $(OutputPath)))\</StartupAssemblyPath>

Expand Down Expand Up @@ -74,5 +82,6 @@
OpenApiSpecificationFiles="$(OpenApiSpecificationFiles)"
OpenApiTreatWarningsAsErrors="$(OpenApiTreatWarningsAsErrors)"
/>
<Touch Files="$(IntermediateOutputPath)$(OpenApiTouchFileName)" AlwaysCreate="true" />
</Target>
</Project>

0 comments on commit 4bcfdd4

Please sign in to comment.