powershell - 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,但我不确定这有什么意义。
对于解决这个非常烦人的问题的任何帮助,我将不胜感激。
解决方案
我有同样的问题。在您的 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 模块。
推荐阅读
- node.js - 无法使用 multer 在 nodejs 中发布空图像文件
- java - 为什么上部转换对象无法访问子类中覆盖的静态方法
- shell - RPM Build,如何在“%post”宏运行的shell脚本中获取RPM包的路径“rpm -ivh”
- javascript - AJAX 响应表单上的 AJAX 无限 preventDefault() (vanilla JS)
- javascript - 检查对象数组中是否存在对象ID
- r - R在标签区域中绘制
- wordpress - 如何在 WordPress 中仅将特定脚本/样式排入队列
- c# - 避免 HashSet 中的重复项
对于略有不同的值 - reactjs - React Router 在本地工作,但在部署到 Heroku 后不起作用
- excel - VBA:在不同的潜艇中使用相同的变量名