首页 > 解决方案 > func 以 PowerShell 和 Az.Storage 开头的奇怪错误

问题描述

我运行了几个基于 PowerShell 的 Azure 函数。我喜欢本地调试功能,但最近我遇到了一个非常尴尬的错误。

当从包含我的函数的库中运行 func start 时,一切都很好,如果这是我第一次在本地启动该函数。但是,如果我停止并重新启动本地功能,则会收到以下错误:

[5/2/2020 2:33:35 PM] EXCEPTION: Import-Module : Az.Storage doesn't support PowerShell Core versions lower than 6.2.4. Please upgrade to PowerShell Core 6.2.4 or higher.
[5/2/2020 2:33:35 PM] + CategoryInfo          : OperationStopped: (Az.Storage doesn't \u2026re 6.2.4 or higher.:String) [Import-Module], RuntimeException
[5/2/2020 2:33:35 PM] + FullyQualifiedErrorId : Az.Storage doesn't support PowerShell Core versions lower than 6.2.4. Please upgrade to PowerShell Core 6.2.4 or higher.,Microsoft.PowerShell.Commands.ImportModuleCommand
[5/2/2020 2:33:35 PM]
[5/2/2020 2:33:35 PM] Script stack trace:
[5/2/2020 2:33:35 PM]    at <ScriptBlock>, C:\Users\AxelBogAndersen\AppData\Local\AzureFunctions\TeamsAppBackend\ManagedDependencies\200501092203881.r\Az.Storage\1.14.0\Az.Storage.psm1: line 41
[5/2/2020 2:33:35 PM]
[5/2/2020 2:33:35 PM] System.Management.Automation.RuntimeException: Az.Storage doesn't support PowerShell Core versions lower than 6.2.4. Please upgrade to PowerShell Core 6.2.4 or higher.
[5/2/2020 2:33:35 PM]    at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)

我正在运行 PowerShell 7.0,因此它高于 6.2.4 - 在 PowerShell 7.1 预览版 2 中产生了相同的错误。

我没有在我的函数中定义任何 Az.Storage 版本,因此最新版本被加载到 ManagedDependencies 库中。目前是 1.14.0 版。

一旦出现错误,它就会保持稳定,直到我删除了 ManagedDependencies 库中的整个文件夹。

我真的很想避免删除依赖包,因为每次我都必须等待下载。下载 256MB 非常耗时烦人。

仅删除 Az.Storage 文件夹不是一个选项 - 下次运行时不会重新加载该模块,并且整个会话会中断。作为一种解决方法,如果存在这样的命令,我可以删除 Az.Storage 并对模块进行强制更新。

我在混合中使用 AzTable,但我不确定这有什么意义。

对于解决这个非常烦人的问题的任何帮助,我将不胜感激。

标签: powershellazure-functions-core-tools

解决方案


我有同样的问题。在您的 Azure Function run.ps1 输出中,psVersion 很可能是 6.2.3。如果你使用 Chocolatey 安装 Azure Function Core Tools 在配置文件中有一个名为 powershellHost 的属性,它使用 Chocolatey 的内置 powershell 主机。

feature name="powershellHost" enabled="true" setExplicitly="false" description="Use Chocolatey's built-in PowerShell host. Available in 0.9.10+." />

我在修改配置文件时遇到了一些麻烦,所以我只是使用 Chocolatey 升级了包并且能够使用 Az 模块。


推荐阅读