Skip to content

Commit 37b7f32

Browse files
committed
Merge branch 'main' into microbuild
2 parents fd52657 + 3b421ec commit 37b7f32

File tree

3 files changed

+130
-24
lines changed

3 files changed

+130
-24
lines changed

tools/Get-3rdPartySymbolFiles.ps1

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
}

tools/Get-SymbolFiles.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $PDBs |% {
4343
}
4444
} |% {
4545
# Collect the DLLs/EXEs as well.
46-
$rootName = "$($_.Directory)/$($_.BaseName)"
46+
$rootName = Join-Path $_.Directory $_.BaseName
4747
if ($rootName.EndsWith('.ni')) {
4848
$rootName = $rootName.Substring(0, $rootName.Length - 3)
4949
}
@@ -64,3 +64,7 @@ $PDBs |% {
6464
Write-Output $_.FullName
6565
}
6666
}
67+
68+
if (!$Tests) {
69+
& $PSScriptRoot\Get-3rdPartySymbolFiles.ps1
70+
}

tools/Install-DotNetSdk.ps1

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ if (!(Test-Path $DotNetInstallScriptRoot)) { New-Item -ItemType Directory -Path
3636
$DotNetInstallScriptRoot = Resolve-Path $DotNetInstallScriptRoot
3737

3838
# Look up actual required .NET SDK version from global.json
39-
$sdkVersion = & "$PSScriptRoot/variables/DotNetSdkVersion.ps1"
39+
$sdks = @(New-Object PSObject -Property @{ Version = & "$PSScriptRoot/variables/DotNetSdkVersion.ps1" })
40+
41+
# Sometimes a repo requires extra SDKs to be installed (e.g. msbuild.locator scenarios running in tests).
42+
# In such a circumstance, a precise SDK version or a channel can be added as in the example below:
43+
# $sdks += New-Object PSObject -Property @{ Channel = '8.0' }
4044

4145
If ($IncludeX86 -and ($IsMacOS -or $IsLinux)) {
4246
Write-Verbose "Ignoring -IncludeX86 switch because 32-bit runtimes are only supported on Windows."
@@ -191,13 +195,16 @@ if ($InstallLocality -eq 'machine') {
191195
$DotNetInstallDir = '/usr/share/dotnet'
192196
} else {
193197
$restartRequired = $false
194-
if ($PSCmdlet.ShouldProcess(".NET SDK $sdkVersion", "Install")) {
195-
Install-DotNet -Version $sdkVersion -Architecture $arch
196-
$restartRequired = $restartRequired -or ($LASTEXITCODE -eq 3010)
197-
198-
if ($IncludeX86) {
199-
Install-DotNet -Version $sdkVersion -Architecture x86
198+
$sdks |% {
199+
if ($_.Version) { $version = $_.Version } else { $version = $_.Channel }
200+
if ($PSCmdlet.ShouldProcess(".NET SDK $_", "Install")) {
201+
Install-DotNet -Version $version -Architecture $arch
200202
$restartRequired = $restartRequired -or ($LASTEXITCODE -eq 3010)
203+
204+
if ($IncludeX86) {
205+
Install-DotNet -Version $version -Architecture x86
206+
$restartRequired = $restartRequired -or ($LASTEXITCODE -eq 3010)
207+
}
201208
}
202209
}
203210

@@ -296,29 +303,33 @@ $DotNetInstallScriptPathExpression = "& '$DotNetInstallScriptPathExpression'"
296303
$anythingInstalled = $false
297304
$global:LASTEXITCODE = 0
298305

299-
if ($PSCmdlet.ShouldProcess(".NET SDK $sdkVersion", "Install")) {
300-
$anythingInstalled = $true
301-
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Version $sdkVersion -Architecture $arch -InstallDir $DotNetInstallDir $switches"
306+
$sdks |% {
307+
if ($_.Version) { $parameters = '-Version', $_.Version } else { $parameters = '-Channel', $_.Channel }
302308

303-
if ($LASTEXITCODE -ne 0) {
304-
Write-Error ".NET SDK installation failure: $LASTEXITCODE"
305-
exit $LASTEXITCODE
306-
}
307-
} else {
308-
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Version $sdkVersion -Architecture $arch -InstallDir $DotNetInstallDir $switches -DryRun"
309-
}
310-
311-
if ($IncludeX86) {
312-
if ($PSCmdlet.ShouldProcess(".NET x86 SDK $sdkVersion", "Install")) {
309+
if ($PSCmdlet.ShouldProcess(".NET SDK $_", "Install")) {
313310
$anythingInstalled = $true
314-
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Version $sdkVersion -Architecture x86 -InstallDir $DotNetX86InstallDir $switches"
311+
Invoke-Expression -Command "$DotNetInstallScriptPathExpression $parameters -Architecture $arch -InstallDir $DotNetInstallDir $switches"
315312

316313
if ($LASTEXITCODE -ne 0) {
317-
Write-Error ".NET x86 SDK installation failure: $LASTEXITCODE"
314+
Write-Error ".NET SDK installation failure: $LASTEXITCODE"
318315
exit $LASTEXITCODE
319316
}
320317
} else {
321-
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Version $sdkVersion -Architecture x86 -InstallDir $DotNetX86InstallDir $switches -DryRun"
318+
Invoke-Expression -Command "$DotNetInstallScriptPathExpression $parameters -Architecture $arch -InstallDir $DotNetInstallDir $switches -DryRun"
319+
}
320+
321+
if ($IncludeX86) {
322+
if ($PSCmdlet.ShouldProcess(".NET x86 SDK $_", "Install")) {
323+
$anythingInstalled = $true
324+
Invoke-Expression -Command "$DotNetInstallScriptPathExpression $parameters -Architecture x86 -InstallDir $DotNetX86InstallDir $switches"
325+
326+
if ($LASTEXITCODE -ne 0) {
327+
Write-Error ".NET x86 SDK installation failure: $LASTEXITCODE"
328+
exit $LASTEXITCODE
329+
}
330+
} else {
331+
Invoke-Expression -Command "$DotNetInstallScriptPathExpression $parameters -Architecture x86 -InstallDir $DotNetX86InstallDir $switches -DryRun"
332+
}
322333
}
323334
}
324335

0 commit comments

Comments
 (0)