|
| 1 | +Function Get-FileFromWeb([Uri]$Uri, $OutFile) { |
| 2 | + $OutDir = Split-Path $OutFile |
| 3 | + if (!(Test-Path $OutFile)) { |
| 4 | + Write-Verbose "Downloading $Uri..." |
| 5 | + if (!(Test-Path $OutDir)) { New-Item -ItemType Directory -Path $OutDir | Out-Null } |
| 6 | + try { |
| 7 | + (New-Object System.Net.WebClient).DownloadFile($Uri, $OutFile) |
| 8 | + } |
| 9 | + finally { |
| 10 | + # This try/finally causes the script to abort |
| 11 | + } |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +Function Unzip($Path, $OutDir) { |
| 16 | + $OutDir = (New-Item -ItemType Directory -Path $OutDir -Force).FullName |
| 17 | + Add-Type -AssemblyName System.IO.Compression.FileSystem |
| 18 | + |
| 19 | + # Start by extracting to a temporary directory so that there are no file conflicts. |
| 20 | + [System.IO.Compression.ZipFile]::ExtractToDirectory($Path, "$OutDir.out") |
| 21 | + |
| 22 | + # Now move all files from the temp directory to $OutDir, overwriting any files. |
| 23 | + Get-ChildItem -Path "$OutDir.out" -Recurse -File | ForEach-Object { |
| 24 | + $destinationPath = Join-Path -Path $OutDir -ChildPath $_.FullName.Substring("$OutDir.out".Length).TrimStart([io.path]::DirectorySeparatorChar, [io.path]::AltDirectorySeparatorChar) |
| 25 | + if (!(Test-Path -Path (Split-Path -Path $destinationPath -Parent))) { |
| 26 | + New-Item -ItemType Directory -Path (Split-Path -Path $destinationPath -Parent) | Out-Null |
| 27 | + } |
| 28 | + Move-Item -Path $_.FullName -Destination $destinationPath -Force |
| 29 | + } |
| 30 | + Remove-Item -Path "$OutDir.out" -Recurse -Force |
| 31 | +} |
| 32 | + |
| 33 | +Function Get-SymbolsFromPackage($id, $version) { |
| 34 | + $symbolPackagesPath = "$PSScriptRoot/../obj/SymbolsPackages" |
| 35 | + New-Item -ItemType Directory -Path $symbolPackagesPath -Force | Out-Null |
| 36 | + $nupkgPath = Join-Path $symbolPackagesPath "$id.$version.nupkg" |
| 37 | + $snupkgPath = Join-Path $symbolPackagesPath "$id.$version.snupkg" |
| 38 | + $unzippedPkgPath = Join-Path $symbolPackagesPath "$id.$version" |
| 39 | + Get-FileFromWeb -Uri "https://www.nuget.org/api/v2/package/$id/$version" -OutFile $nupkgPath |
| 40 | + Get-FileFromWeb -Uri "https://www.nuget.org/api/v2/symbolpackage/$id/$version" -OutFile $snupkgPath |
| 41 | + |
| 42 | + Unzip -Path $nupkgPath -OutDir $unzippedPkgPath |
| 43 | + Unzip -Path $snupkgPath -OutDir $unzippedPkgPath |
| 44 | + |
| 45 | + Get-ChildItem -Recurse -LiteralPath $unzippedPkgPath -Filter *.pdb | % { |
| 46 | + # Collect the DLLs/EXEs as well. |
| 47 | + $rootName = Join-Path $_.Directory $_.BaseName |
| 48 | + if ($rootName.EndsWith('.ni')) { |
| 49 | + $rootName = $rootName.Substring(0, $rootName.Length - 3) |
| 50 | + } |
| 51 | + |
| 52 | + $dllPath = "$rootName.dll" |
| 53 | + $exePath = "$rootName.exe" |
| 54 | + if (Test-Path $dllPath) { |
| 55 | + $BinaryImagePath = $dllPath |
| 56 | + } |
| 57 | + elseif (Test-Path $exePath) { |
| 58 | + $BinaryImagePath = $exePath |
| 59 | + } |
| 60 | + else { |
| 61 | + Write-Warning "`"$_`" found with no matching binary file." |
| 62 | + $BinaryImagePath = $null |
| 63 | + } |
| 64 | + |
| 65 | + if ($BinaryImagePath) { |
| 66 | + Write-Output $BinaryImagePath |
| 67 | + Write-Output $_.FullName |
| 68 | + } |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +Function Get-PackageVersion($id) { |
| 73 | + $versionProps = [xml](Get-Content -LiteralPath $PSScriptRoot\..\Directory.Packages.props) |
| 74 | + $version = $versionProps.Project.ItemGroup.PackageVersion | ? { $_.Include -eq $id } | % { $_.Version } |
| 75 | + if (!$version) { |
| 76 | + Write-Error "No package version found in Directory.Packages.props for the package '$id'" |
| 77 | + } |
| 78 | + |
| 79 | + $version |
| 80 | +} |
| 81 | + |
| 82 | +# All 3rd party packages for which symbols packages are expected should be listed here. |
| 83 | +# These must all be sourced from nuget.org, as it is the only feed that supports symbol packages. |
| 84 | +$3rdPartyPackageIds = @() |
| 85 | + |
| 86 | +$3rdPartyPackageIds | % { |
| 87 | + $version = Get-PackageVersion $_ |
| 88 | + if ($version) { |
| 89 | + Get-SymbolsFromPackage -id $_ -version $version |
| 90 | + } |
| 91 | +} |
0 commit comments