Skip to content

Commit bad9870

Browse files
committed
Improve 'Restore' build task to only restore packages when necessary
1 parent 5e6486f commit bad9870

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

PowerShellEditorServices.build.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,15 @@ task SetupDotNet -Before Restore, Clean, Build, BuildHost, Test, TestPowerShellA
8989
Write-Host "`n### Using dotnet v$requiredSDKVersion at path $script:dotnetExe`n" -ForegroundColor Green
9090
}
9191

92-
task Restore {
92+
function NeedsRestore($rootPath) {
93+
# This checks to see if the number of folders under a given
94+
# path (like "src" or "test") is greater than the number of
95+
# obj\project.assets.json files found under that path, implying
96+
# that those folders have not yet been restored.
97+
return (Get-ChildItem $rootPath).Length -gt (Get-ChildItem "$rootPath\*\obj\project.assets.json").Length
98+
}
99+
100+
task Restore -If { "Restore" -in $BuildTask -or (NeedsRestore(".\src")) -or (NeedsRestore(".\test")) } -Before Clean, Build, BuildHost, Test {
93101
exec { & $script:dotnetExe restore }
94102
}
95103

@@ -199,4 +207,4 @@ task UploadTestLogs -After Test -If ($script:IsCIBuild) {
199207
}
200208

201209
# The default task is to run the entire CI build
202-
task . GetProductVersion, Restore, Clean, Build, TestPowerShellApi, Test, PackageNuGet, PackageModule, UploadArtifacts
210+
task . GetProductVersion, Clean, Build, TestPowerShellApi, Test, PackageNuGet, PackageModule, UploadArtifacts

0 commit comments

Comments
 (0)