|
Expand Up
|
@@ -94,9 +94,9 @@ |
|
|
Determines timeout duration in seconds for downloading of the SDK file |
|
|
Default: 1200 seconds (20 minutes) |
|
|
.PARAMETER KeepZip |
|
|
If set, downloaded file is kept |
|
|
If set, downloaded archive file is kept. Applies to both .zip and .tar.gz formats. |
|
|
.PARAMETER ZipPath |
|
|
Use that path to store installer, generated by default |
|
|
Use that path to store the downloaded archive, generated by default. Applies to both .zip and .tar.gz formats. |
|
|
.EXAMPLE |
|
|
dotnet-install.ps1 -Version 7.0.401 |
|
|
Installs the .NET SDK version 7.0.401 |
|
Expand Down
Expand Up
|
@@ -341,6 +341,36 @@ function Get-NormalizedProduct([string]$Runtime) { |
|
|
} |
|
|
} |
|
|
|
|
|
function Test-TarAvailable { |
|
|
if ($env:DOTNET_INSTALL_SKIP_TAR -eq "1") { |
|
|
Say-Verbose "Skipping tar detection due to DOTNET_INSTALL_SKIP_TAR environment variable." |
|
|
return $false |
|
|
} |
|
|
$tarCommand = Get-Command -Name "tar" -ErrorAction SilentlyContinue |
|
|
return $null -ne $tarCommand |
|
|
} |
|
|
|
|
|
function Get-FileExtension-For-Version([string]$VersionOrChannel) { |
|
|
if (-not $script:TarAvailable) { |
|
|
return ".zip" |
|
|
} |
|
|
if ($VersionOrChannel -match '^(\d+)\.') { |
|
|
$majorVersion = [int]$Matches[1] |
|
|
if ($majorVersion -ge 11) { |
|
|
# Windows tarballs are only available starting with 11.0 preview 3 |
|
|
if ($VersionOrChannel -match 'preview\.(\d+)') { |
|
|
$previewNum = [int]$Matches[1] |
|
|
if ($majorVersion -eq 11 -and $previewNum -lt 3) { |
|
|
Say-Verbose "Version '$VersionOrChannel' predates tar.gz availability; using zip." |
|
|
return ".zip" |
|
|
} |
|
|
} |
|
|
Say-Verbose "Using tar.gz archive format for version/channel '$VersionOrChannel'." |
|
|
return ".tar.gz" |
|
|
} |
|
|
} |
|
|
return ".zip" |
|
|
} |
|
|
|
|
|
# The version text returned from the feeds is a 1-line or 2-line string: |
|
|
# For the SDK and the dotnet runtime (2 lines): |
|
Expand Down
Expand Up
|
@@ -594,24 +624,27 @@ function Get-Download-Link([string]$AzureFeed, [string]$SpecificVersion, [string |
|
|
# If anything fails in this lookup it will default to $SpecificVersion |
|
|
$SpecificProductVersion = Get-Product-Version -AzureFeed $AzureFeed -SpecificVersion $SpecificVersion |
|
|
|
|
|
# For .NET 11.0+, tar.gz is the preferred archive format on Windows |
|
|
$ext = Get-FileExtension-For-Version $SpecificVersion |
|
|
|
|
|
if ($Runtime -eq "dotnet") { |
|
|
$PayloadURL = "$AzureFeed/Runtime/$SpecificVersion/dotnet-runtime-$SpecificProductVersion-win-$CLIArchitecture.zip" |
|
|
$PayloadURL = "$AzureFeed/Runtime/$SpecificVersion/dotnet-runtime-$SpecificProductVersion-win-$CLIArchitecture$ext" |
|
|
} |
|
|
elseif ($Runtime -eq "aspnetcore") { |
|
|
$PayloadURL = "$AzureFeed/aspnetcore/Runtime/$SpecificVersion/aspnetcore-runtime-$SpecificProductVersion-win-$CLIArchitecture.zip" |
|
|
$PayloadURL = "$AzureFeed/aspnetcore/Runtime/$SpecificVersion/aspnetcore-runtime-$SpecificProductVersion-win-$CLIArchitecture$ext" |
|
|
} |
|
|
elseif ($Runtime -eq "windowsdesktop") { |
|
|
# The windows desktop runtime is part of the core runtime layout prior to 5.0 |
|
|
$PayloadURL = "$AzureFeed/Runtime/$SpecificVersion/windowsdesktop-runtime-$SpecificProductVersion-win-$CLIArchitecture.zip" |
|
|
$PayloadURL = "$AzureFeed/Runtime/$SpecificVersion/windowsdesktop-runtime-$SpecificProductVersion-win-$CLIArchitecture$ext" |
|
|
if ($SpecificVersion -match '^(\d+)\.(.*)$') { |
|
|
$majorVersion = [int]$Matches[1] |
|
|
if ($majorVersion -ge 5) { |
|
|
$PayloadURL = "$AzureFeed/WindowsDesktop/$SpecificVersion/windowsdesktop-runtime-$SpecificProductVersion-win-$CLIArchitecture.zip" |
|
|
$PayloadURL = "$AzureFeed/WindowsDesktop/$SpecificVersion/windowsdesktop-runtime-$SpecificProductVersion-win-$CLIArchitecture$ext" |
|
|
} |
|
|
} |
|
|
} |
|
|
elseif (-not $Runtime) { |
|
|
$PayloadURL = "$AzureFeed/Sdk/$SpecificVersion/dotnet-sdk-$SpecificProductVersion-win-$CLIArchitecture.zip" |
|
|
$PayloadURL = "$AzureFeed/Sdk/$SpecificVersion/dotnet-sdk-$SpecificProductVersion-win-$CLIArchitecture$ext" |
|
|
} |
|
|
else { |
|
|
throw "Invalid value for `$Runtime" |
|
Expand Down
Expand Up
|
@@ -877,6 +910,80 @@ function Extract-Dotnet-Package([string]$ZipPath, [string]$OutPath) { |
|
|
} |
|
|
} |
|
|
|
|
|
function Extract-Dotnet-Package-Tar([string]$TarPath, [string]$OutPath) { |
|
|
Say-Invocation $MyInvocation |
|
|
|
|
|
New-Item -ItemType Directory -Force -Path $OutPath | Out-Null |
|
|
|
|
|
# Build an exclude list of versioned directories that already exist locally. |
|
|
# This matches the zip extraction behavior: if shared/Microsoft.NETCore.App/11.0.0/ |
|
|
# already exists, we skip all files under that version to avoid overwriting a |
|
|
# previously installed version. |
|
|
$excludeArgs = @() |
|
|
$versionRegex = '.*/\d+\.\d+[^/]+/' |
|
|
|
|
|
# Read the tarball's file listing to discover versioned directory prefixes |
|
|
$tarListing = & tar -tzf $TarPath 2>$null |
|
|
$versionedDirs = @{} |
|
|
foreach ($entry in $tarListing) { |
|
|
$normalizedEntry = $entry.Replace('\', '/') |
|
|
$match = [regex]::Match($normalizedEntry, $versionRegex) |
|
|
if ($match.Success) { |
|
|
$versionedPrefix = $normalizedEntry.Substring(0, $match.Index + $match.Length) |
|
|
if (-not $versionedDirs.ContainsKey($versionedPrefix)) { |
|
|
$localDir = Join-Path -Path $OutPath -ChildPath $versionedPrefix |
|
|
$versionedDirs[$versionedPrefix] = (Test-Path $localDir -PathType Container) |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
foreach ($dir in $versionedDirs.GetEnumerator()) { |
|
|
if ($dir.Value) { |
|
|
# This versioned directory already exists — exclude it from extraction |
|
|
$pattern = $dir.Key + '*' |
|
|
$excludeArgs += '--exclude' |
|
|
$excludeArgs += $pattern |
|
|
Say-Verbose "Excluding pre-existing versioned directory: $($dir.Key)" |
|
|
} |
|
|
} |
|
|
|
|
|
# Handle non-versioned file override logic. |
|
|
# If OverrideNonVersionedFiles is false, exclude non-versioned files that already exist. |
|
|
if (-not $OverrideNonVersionedFiles) { |
|
|
foreach ($entry in $tarListing) { |
|
|
$normalizedEntry = $entry.Replace('\', '/') |
|
|
# Skip directory entries (end with /) |
|
|
if ($normalizedEntry.EndsWith('/')) { continue } |
|
|
$match = [regex]::Match($normalizedEntry, $versionRegex) |
|
|
if (-not $match.Success) { |
|
|
# Non-versioned file — exclude if it already exists locally |
|
|
$localPath = Join-Path -Path $OutPath -ChildPath $normalizedEntry |
|
|
if (Test-Path $localPath) { |
|
|
$excludeArgs += '--exclude' |
|
|
$excludeArgs += $normalizedEntry |
|
|
Say-Verbose "Excluding pre-existing non-versioned file: $normalizedEntry" |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
try { |
|
|
# Extract directly to install root, preserving hard links |
|
|
$tarOutput = & tar -xzf $TarPath -C $OutPath @excludeArgs 2>&1 |
|
|
if ($LASTEXITCODE -ne 0) { |
|
|
$tarOutputText = ($tarOutput | Out-String).Trim() |
|
|
if ([string]::IsNullOrWhiteSpace($tarOutputText)) { |
|
|
throw "Tar extraction failed with exit code $LASTEXITCODE." |
|
|
} |
|
|
throw "Tar extraction failed with exit code $LASTEXITCODE. tar output: $tarOutputText" |
|
|
} |
|
|
} |
|
|
catch { |
|
|
Say-Error "Failed to extract tar package. Exception: $_" |
|
|
throw |
|
|
} |
|
|
} |
|
|
|
|
|
function DownloadFile($Source, [string]$OutPath) { |
|
|
if ($Source -notlike "http*") { |
|
|
# Using System.IO.Path.GetFullPath to get the current directory |
|
Expand Down
Expand Up
|
@@ -991,7 +1098,7 @@ function PrintDryRunOutput($Invocation, $DownloadLinks) { |
|
|
} |
|
|
} |
|
|
|
|
|
function Get-AkaMSDownloadLink([string]$Channel, [string]$Quality, [bool]$Internal, [string]$Product, [string]$Architecture) { |
|
|
function Get-AkaMSDownloadLink([string]$Channel, [string]$Quality, [bool]$Internal, [string]$Product, [string]$Architecture, [string]$FileExtension = ".zip") { |
|
|
Say-Invocation $MyInvocation |
|
|
|
|
|
#quality is not supported for LTS or STS channel |
|
Expand All
|
@@ -1010,7 +1117,7 @@ function Get-AkaMSDownloadLink([string]$Channel, [string]$Quality, [bool]$Intern |
|
|
if (-not [string]::IsNullOrEmpty($Quality)) { |
|
|
$akaMsLink += "/$Quality" |
|
|
} |
|
|
$akaMsLink += "/$Product-win-$Architecture.zip" |
|
|
$akaMsLink += "/$Product-win-$Architecture$FileExtension" |
|
|
Say-Verbose "Constructed aka.ms link: '$akaMsLink'." |
|
|
$akaMsDownloadLink = $null |
|
|
|
|
Expand Down
Expand Up
|
@@ -1062,7 +1169,23 @@ function Get-AkaMSDownloadLink([string]$Channel, [string]$Quality, [bool]$Intern |
|
|
} |
|
|
|
|
|
function Get-AkaMsLink-And-Version([string] $NormalizedChannel, [string] $NormalizedQuality, [bool] $Internal, [string] $ProductName, [string] $Architecture) { |
|
|
$AkaMsDownloadLink = Get-AkaMSDownloadLink -Channel $NormalizedChannel -Quality $NormalizedQuality -Internal $Internal -Product $ProductName -Architecture $Architecture |
|
|
|
|
|
# When tar is available, try .tar.gz first via aka.ms, then fall back to .zip. |
|
|
# This handles symbolic channels (STS/LTS) and numeric channels where tar.gz |
|
|
# may not yet be available (e.g. pre-11.0 versions). |
|
|
$extensionsToTry = @(".zip") |
|
|
if ($script:TarAvailable) { |
|
|
$extensionsToTry = @(".tar.gz", ".zip") |
|
|
} |
|
|
|
|
|
$AkaMsDownloadLink = $null |
|
|
foreach ($ext in $extensionsToTry) { |
|
|
$AkaMsDownloadLink = Get-AkaMSDownloadLink -Channel $NormalizedChannel -Quality $NormalizedQuality -Internal $Internal -Product $ProductName -Architecture $Architecture -FileExtension $ext |
|
|
if (-not [string]::IsNullOrEmpty($AkaMsDownloadLink)) { |
|
|
break |
|
|
} |
|
|
Say-Verbose "aka.ms link resolution with '$ext' extension failed, trying next format." |
|
|
} |
|
|
|
|
|
if ([string]::IsNullOrEmpty($AkaMsDownloadLink)) { |
|
|
if (-not [string]::IsNullOrEmpty($NormalizedQuality)) { |
|
Expand Down
Expand Up
|
@@ -1191,6 +1314,8 @@ Measure-Action "Product discovery" { |
|
|
$script:NormalizedProduct = Get-NormalizedProduct $Runtime |
|
|
Say-Verbose "Normalized product: '$NormalizedProduct'" |
|
|
$script:FeedCredential = ValidateFeedCredential $FeedCredential |
|
|
$script:TarAvailable = Test-TarAvailable |
|
|
Say-Verbose "Tar available: '$TarAvailable'" |
|
|
} |
|
|
|
|
|
$InstallRoot = Resolve-Installation-Path $InstallDir |
|
Expand Down
Expand Up
|
@@ -1319,7 +1444,12 @@ if (-not $DownloadSucceeded) { |
|
|
} |
|
|
|
|
|
Say "Extracting the archive." |
|
|
Measure-Action "Package extraction" { Extract-Dotnet-Package -ZipPath $ZipPath -OutPath $InstallRoot } |
|
|
if ($DownloadedLink.downloadLink.EndsWith(".tar.gz")) { |
|
|
Measure-Action "Package extraction" { Extract-Dotnet-Package-Tar -TarPath $ZipPath -OutPath $InstallRoot } |
|
|
} |
|
|
else { |
|
|
Measure-Action "Package extraction" { Extract-Dotnet-Package -ZipPath $ZipPath -OutPath $InstallRoot } |
|
|
} |
|
|
|
|
|
# Check if the SDK version is installed; if not, fail the installation. |
|
|
$isAssetInstalled = $false |
|
Expand Down
|
|