Merge pull request #4000 from MichaelSimons/nanoInstaller
Modified dotnet-install.ps1 to support Nano Server
This commit is contained in:
commit
49527d3ea6
1 changed files with 48 additions and 7 deletions
55
scripts/obtain/dotnet-install.ps1
vendored
55
scripts/obtain/dotnet-install.ps1
vendored
|
@ -115,6 +115,16 @@ function Get-Version-Info-From-Version-Text([string]$VersionText) {
|
||||||
return $VersionInfo
|
return $VersionInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Load-Assembly([string] $Assembly) {
|
||||||
|
try {
|
||||||
|
Add-Type -Assembly $Assembly | Out-Null
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
# On Nano Server, Powershell Core Edition is used. Add-Type is unable to resolve base class assemblies because they are not GAC'd.
|
||||||
|
# Loading the base class assemblies is not unnecessary as the types will automatically get resolved.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Get-Latest-Version-Info([string]$AzureFeed, [string]$AzureChannel, [string]$CLIArchitecture) {
|
function Get-Latest-Version-Info([string]$AzureFeed, [string]$AzureChannel, [string]$CLIArchitecture) {
|
||||||
Say-Invocation $MyInvocation
|
Say-Invocation $MyInvocation
|
||||||
|
|
||||||
|
@ -126,12 +136,23 @@ function Get-Latest-Version-Info([string]$AzureFeed, [string]$AzureChannel, [str
|
||||||
$VersionFileUrl = "$AzureFeed/Sdk/$AzureChannel/latest.version"
|
$VersionFileUrl = "$AzureFeed/Sdk/$AzureChannel/latest.version"
|
||||||
}
|
}
|
||||||
|
|
||||||
$Response = Invoke-WebRequest -UseBasicParsing $VersionFileUrl
|
try {
|
||||||
|
# HttpClient is used vs Invoke-WebRequest in order to support Nano Server which doesn't support the Invoke-WebRequest cmdlet.
|
||||||
|
Load-Assembly -Assembly System.Net.Http
|
||||||
|
$HttpClient = New-Object System.Net.Http.HttpClient
|
||||||
|
$Response = $HttpClient.GetAsync($VersionFileUrl).Result
|
||||||
|
$StringContent = $Response.Content.ReadAsStringAsync().Result
|
||||||
|
|
||||||
switch ($Response.Headers.'Content-Type'){
|
switch ($Response.Content.Headers.ContentType) {
|
||||||
{ ($_ -eq "application/octet-stream") } { $VersionText = [Text.Encoding]::UTF8.GetString($Response.Content) }
|
{ ($_ -eq "application/octet-stream") } { $VersionText = [Text.Encoding]::UTF8.GetString($StringContent) }
|
||||||
{ ($_ -eq "text/plain") } { $VersionText = $Response.Content }
|
{ ($_ -eq "text/plain") } { $VersionText = $StringContent }
|
||||||
default { throw "``$Response.Headers.'Content-Type'`` is an unknown .version file content type." }
|
default { throw "``$Response.Content.Headers.ContentType`` is an unknown .version file content type." }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if ($HttpClient -ne $null) {
|
||||||
|
$HttpClient.Dispose()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -281,7 +302,7 @@ function Get-List-Of-Directories-And-Versions-To-Unpack-From-Dotnet-Package([Sys
|
||||||
function Extract-Dotnet-Package([string]$ZipPath, [string]$OutPath) {
|
function Extract-Dotnet-Package([string]$ZipPath, [string]$OutPath) {
|
||||||
Say-Invocation $MyInvocation
|
Say-Invocation $MyInvocation
|
||||||
|
|
||||||
Add-Type -Assembly System.IO.Compression.FileSystem | Out-Null
|
Load-Assembly -Assembly System.IO.Compression.FileSystem
|
||||||
Set-Variable -Name Zip
|
Set-Variable -Name Zip
|
||||||
try {
|
try {
|
||||||
$Zip = [System.IO.Compression.ZipFile]::OpenRead($ZipPath)
|
$Zip = [System.IO.Compression.ZipFile]::OpenRead($ZipPath)
|
||||||
|
@ -308,6 +329,26 @@ function Extract-Dotnet-Package([string]$ZipPath, [string]$OutPath) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function DownloadFile([Uri]$Uri, [string]$OutPath) {
|
||||||
|
try {
|
||||||
|
# HttpClient is used vs Invoke-WebRequest in order to support Nano Server which doesn't support the Invoke-WebRequest cmdlet.
|
||||||
|
Load-Assembly -Assembly System.Net.Http
|
||||||
|
$HttpClient = New-Object System.Net.Http.HttpClient
|
||||||
|
$Stream = $HttpClient.GetAsync($Uri).Result.Content.ReadAsStreamAsync().Result
|
||||||
|
$File = [System.IO.File]::Create($OutPath)
|
||||||
|
$Stream.CopyTo($File)
|
||||||
|
$File.Close()
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if ($HttpClient -ne $null) {
|
||||||
|
$HttpClient.Dispose()
|
||||||
|
}
|
||||||
|
if ($Stream -ne $null) {
|
||||||
|
$Stream.Dispose()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$AzureChannel = Get-Azure-Channel-From-Channel -Channel $Channel
|
$AzureChannel = Get-Azure-Channel-From-Channel -Channel $Channel
|
||||||
$CLIArchitecture = Get-CLIArchitecture-From-Architecture $Architecture
|
$CLIArchitecture = Get-CLIArchitecture-From-Architecture $Architecture
|
||||||
$SpecificVersion = Get-Specific-Version-From-Version -AzureFeed $AzureFeed -AzureChannel $AzureChannel -CLIArchitecture $CLIArchitecture -Version $Version
|
$SpecificVersion = Get-Specific-Version-From-Version -AzureFeed $AzureFeed -AzureChannel $AzureChannel -CLIArchitecture $CLIArchitecture -Version $Version
|
||||||
|
@ -337,7 +378,7 @@ New-Item -ItemType Directory -Force -Path $InstallRoot | Out-Null
|
||||||
foreach ($DownloadLink in $DownloadLinks) {
|
foreach ($DownloadLink in $DownloadLinks) {
|
||||||
$ZipPath = [System.IO.Path]::GetTempFileName()
|
$ZipPath = [System.IO.Path]::GetTempFileName()
|
||||||
Say "Downloading $DownloadLink"
|
Say "Downloading $DownloadLink"
|
||||||
$resp = Invoke-WebRequest -UseBasicParsing $DownloadLink -OutFile $ZipPath
|
DownloadFile -Uri $DownloadLink -OutPath $ZipPath
|
||||||
|
|
||||||
Say "Extracting zip from $DownloadLink"
|
Say "Extracting zip from $DownloadLink"
|
||||||
Extract-Dotnet-Package -ZipPath $ZipPath -OutPath $InstallRoot
|
Extract-Dotnet-Package -ZipPath $ZipPath -OutPath $InstallRoot
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue