From 66ab86f1e02fbe9f7aa32f9c579a58a0b657d0fe Mon Sep 17 00:00:00 2001 From: "Erich(Renyong) Wang" Date: Tue, 14 Apr 2020 16:16:55 +0800 Subject: [PATCH] Check PS Version when importing Az.Storage which using Azure.Core --- tools/AzureRM.Example.psm1 | 6 ++++-- tools/UpdateModules.ps1 | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tools/AzureRM.Example.psm1 b/tools/AzureRM.Example.psm1 index 978cc858e6ac..c0f96b1e6c13 100644 --- a/tools/AzureRM.Example.psm1 +++ b/tools/AzureRM.Example.psm1 @@ -34,6 +34,8 @@ if (%ISAZMODULE% -and ($PSEdition -eq 'Desktop')) Test-DotNet } +%AZURECOREPREREQUISITE% + if (Test-Path -Path "$PSScriptRoot\StartupScripts" -ErrorAction Ignore) { Get-ChildItem "$PSScriptRoot\StartupScripts" -ErrorAction Stop | ForEach-Object { @@ -60,7 +62,7 @@ if($PSEdition -eq 'Desktop' -and (Test-Path $preloadPath -ErrorAction Ignore)) Add-Type -Path $_.FullName -ErrorAction Ignore | Out-Null } catch { - Write-Warning $_ + Write-Verbose $_ } } } @@ -83,7 +85,7 @@ if($PSEdition -eq 'Core' -and (Test-Path $netCorePath -ErrorAction Ignore)) Add-Type -Path $_.FullName -ErrorAction Ignore | Out-Null } catch { - Write-Warning $_ + Write-Verbose $_ } } } diff --git a/tools/UpdateModules.ps1 b/tools/UpdateModules.ps1 index fde3dc620df9..81ab1f9197d8 100644 --- a/tools/UpdateModules.ps1 +++ b/tools/UpdateModules.ps1 @@ -95,6 +95,24 @@ function New-ModulePsm1 { $template = $template -replace "%DATE%", [string](Get-Date) $template = $template -replace "%IMPORTED-DEPENDENCIES%", $importedModules + #Az.Storage is using Azure.Core, so need to check PS version + if ($IsNetcore -and $file.BaseName -eq 'Az.Storage') + { + $template = $template -replace "%AZURECOREPREREQUISITE%", +@" +if (%ISAZMODULE% -and (`$PSEdition -eq 'Core')) +{ + if (`$PSVersionTable.PSVersion -lt [Version]'6.2.4') + { + throw "Az.Storage doesn't support PowerShell Core versions lower than 6.2.4. Please upgrade to PowerShell Core 6.2.4 or higher." + } +} +"@ + } + else + { + $template = $template -replace "%AZURECOREPREREQUISITE%", "" + } # Replace Az or AzureRM with correct information if ($IsNetcore) {