2019-06-28 13:15:43 +00:00
|
|
|
param(
|
|
|
|
[Parameter(Mandatory=$true)][string] $InputPath, # Full path to directory where artifact packages are stored
|
|
|
|
[Parameter(Mandatory=$true)][string] $ExtractPath # Full path to directory where the packages will be extracted
|
|
|
|
)
|
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
$ErrorActionPreference = 'Stop'
|
2019-06-28 13:15:43 +00:00
|
|
|
Set-StrictMode -Version 2.0
|
2019-09-26 21:15:58 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
$disableConfigureToolsetImport = $true
|
2019-09-26 21:15:58 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
function ExtractArtifacts {
|
2019-06-28 13:15:43 +00:00
|
|
|
if (!(Test-Path $InputPath)) {
|
|
|
|
Write-Host "Input Path does not exist: $InputPath"
|
|
|
|
ExitWithExitCode 0
|
|
|
|
}
|
|
|
|
$Jobs = @()
|
|
|
|
Get-ChildItem "$InputPath\*.nupkg" |
|
|
|
|
ForEach-Object {
|
|
|
|
$Jobs += Start-Job -ScriptBlock $ExtractPackage -ArgumentList $_.FullName
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($Job in $Jobs) {
|
|
|
|
Wait-Job -Id $Job.Id | Receive-Job
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2020-03-31 13:04:58 +00:00
|
|
|
# `tools.ps1` checks $ci to perform some actions. Since the SDL
|
|
|
|
# scripts don't necessarily execute in the same agent that run the
|
|
|
|
# build.ps1/sh script this variable isn't automatically set.
|
|
|
|
$ci = $true
|
2019-11-22 13:41:58 +00:00
|
|
|
. $PSScriptRoot\..\tools.ps1
|
|
|
|
|
|
|
|
$ExtractPackage = {
|
|
|
|
param(
|
|
|
|
[string] $PackagePath # Full path to a NuGet package
|
|
|
|
)
|
2023-08-02 12:13:56 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
if (!(Test-Path $PackagePath)) {
|
|
|
|
Write-PipelineTelemetryError -Category 'Build' -Message "Input file does not exist: $PackagePath"
|
|
|
|
ExitWithExitCode 1
|
|
|
|
}
|
2023-08-02 12:13:56 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
$RelevantExtensions = @('.dll', '.exe', '.pdb')
|
|
|
|
Write-Host -NoNewLine 'Extracting ' ([System.IO.Path]::GetFileName($PackagePath)) '...'
|
2023-08-02 12:13:56 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
$PackageId = [System.IO.Path]::GetFileNameWithoutExtension($PackagePath)
|
|
|
|
$ExtractPath = Join-Path -Path $using:ExtractPath -ChildPath $PackageId
|
2023-08-02 12:13:56 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
2023-08-02 12:13:56 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
[System.IO.Directory]::CreateDirectory($ExtractPath);
|
2023-08-02 12:13:56 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
try {
|
|
|
|
$zip = [System.IO.Compression.ZipFile]::OpenRead($PackagePath)
|
|
|
|
|
|
|
|
$zip.Entries |
|
|
|
|
Where-Object {$RelevantExtensions -contains [System.IO.Path]::GetExtension($_.Name)} |
|
|
|
|
ForEach-Object {
|
2023-08-02 12:13:56 +00:00
|
|
|
$TargetPath = Join-Path -Path $ExtractPath -ChildPath (Split-Path -Path $_.FullName)
|
|
|
|
[System.IO.Directory]::CreateDirectory($TargetPath);
|
|
|
|
|
|
|
|
$TargetFile = Join-Path -Path $ExtractPath -ChildPath $_.FullName
|
|
|
|
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, $TargetFile)
|
2019-11-22 13:41:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch {
|
2020-04-24 17:34:25 +00:00
|
|
|
Write-Host $_
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message $_
|
|
|
|
ExitWithExitCode 1
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
$zip.Dispose()
|
|
|
|
}
|
|
|
|
}
|
2019-06-28 13:15:43 +00:00
|
|
|
Measure-Command { ExtractArtifacts }
|
|
|
|
}
|
|
|
|
catch {
|
2020-04-24 17:34:25 +00:00
|
|
|
Write-Host $_
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message $_
|
2019-06-28 13:15:43 +00:00
|
|
|
ExitWithExitCode 1
|
|
|
|
}
|