在IntelliJ本地运行Azure Function时遇“Failed to get version of function(null)”错误
检查Azure Functions Core Tools的系统环境变量
确保azfunc或func命令能在系统终端(非IntelliJ内置终端)正常执行,输入func --version能返回有效版本号。如果执行失败,手动把Core Tools的安装路径添加到系统PATH变量:Windows默认路径一般是C:\Program Files\Microsoft\Azure Functions Core Tools,Mac/Linux通常是/usr/local/azure-functions-core-tools。手动指定IntelliJ中Core Tools的路径
打开IntelliJ的设置(Settings -> Tools -> Azure Functions),不要依赖自动检测,直接点击浏览按钮,选中Core Tools安装目录下的func.exe(Windows)或func(Mac/Linux)可执行文件,保存后重启IntelliJ重试。清理IntelliJ的插件缓存
关闭IntelliJ,找到对应缓存目录:- Windows:
C:\Users\<你的用户名>\.IntelliJIdea<版本>\system\caches - Mac:
~/Library/Caches/JetBrains/IntelliJIdea<版本> - Linux:
~/.cache/JetBrains/IntelliJIdea<版本>
删除其中带azure字样的缓存文件夹,或者直接清空caches目录,之后重新打开IntelliJ。
- Windows:
核对项目Runtime版本与Core Tools兼容性
打开项目根目录的host.json,确认version字段和已安装的Core Tools版本匹配:Core Tools v4对应runtime 4.x,v3对应3.x。版本不匹配的话,要么修改host.json的version值,要么安装对应版本的Core Tools。重置Azure插件配置
进入Settings -> Plugins,找到Azure Tools,点击右侧齿轮图标选择Uninstall,卸载后先重启IntelliJ,再重新安装最新稳定版的Azure Tools插件,安装完成后再次重启IntelliJ并重新配置路径。
内容的提问来源于stack exchange,提问作者Onki

