当您通过 NPM 安装 Azure Functions Core Tools 2.x Runtime 时,Visual Studio 2017 中 .NET Core 2.0 / .NET Standard 2.0 Azure Functions 项目的正确答案
我关注了@ahmelsayed 的回答,特别是@ravinsp 的.net core 2.0 cmets 的cmets。虽然非常有帮助并使我走上正轨,但如果没有关键且非直观的修改,它们对我不起作用,所以我添加了一个新的答案。
TL;DR;
如果你使用 NPM 安装 Azure Functions Core Tools 2.x Runtime,那么你可能需要将 Project/Properties/Debug/Application Arguments 设置为:
C:\Users\<myuserid>\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\func.dll host start --port 8888 --pause-on-error
下面是长答案...
我的设置
在本练习中,我的设置完全是最新的(在撰写本文时),如下所示:
- Visual Studio 2017 专业版:15.6.2
- Azure Functions 和 Web 作业工具:15.0.40215.0
- Windows 10 10.0.16299 内部版本 16299
-
Azure Functions Core Tools(根据 Microsoft 的 Develop and run Azure functions locally 文档安装)报告(在 Git Bash 中):
me@MYDESKTOP ~
$ func
<snip/>
Azure Functions Core Tools (2.0.1-beta.24)
Function Runtime Version: 2.0.11587.0
fwiw,Azure 上此 Functions App 的 Functions App 设置选项卡显示:
Runtime version: 2.0.11587.0 (beta)
我的问题
当我运行我的函数项目(没有应用程序参数)时,我在控制台输出中得到了这个:
[17/03/2018 21:06:38] Starting Host (HostId=MYMACHINE, Version=2.0.11353.0, ProcessId=<snip/>
Listening on http://localhost:7071/
这本身可能不是问题,但我越来越讨厌“在我的机器上工作,发布到 azure 时失败”类型的问题,所以我想确保本地执行使用与运行时相同的函数天蓝色(即 2.0.11587.0,根据上面的设置说明,它是/应该是,对吧?)
因此,根据@ravinsp 的说明,我在我的 C 驱动器上运行查找以找到 Azure.Functions.Cli.dll - 只有一个,它位于 C:\Users\<myuserid>\AppData\Local\Azure.Functions.V2.Cli\2.0.1-beta\Azure.Functions.Cli.dll,这似乎与 @ravinsp 的答案非常一致。
所以,我添加了以下项目/属性/调试/应用程序参数:
C:\Users\<myuserid>\AppData\Local\Azure.Functions.V2.Cli\2.0.1-beta\Azure.Functions.Cli.dll host start --port 8888 --pause-on-error
然后我得到端口 8888,但奇怪的是运行时 仍然被报告为 2.0.11353。
[17/03/2018 21:13:02] Starting Host (HostId=MYMACHINE, Version=2.0.11353.0, ProcessId=<snip/>
Listening on http://localhost:8888/
解决方案
鉴于按照上述从 Git Bash 运行的 func 显示运行时为 2.0.11587.0,我尝试了 which func,它返回了 /c/Users/<myuserid>/AppData/Roaming/npm/func
。我在上面做了一只猫,长话短说,我可以看到它最终运行的是C:\Users\<myuserid>\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\func.exe,并且在同一个目录中有一个func.dll。
所以,我尝试了以下项目/属性/调试/应用程序参数:
C:\Users\<myuserid>\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\func.dll host start --port 8888 --pause-on-error
那我终于明白了……
[17/03/2018 21:16:29] Starting Host (HostId=MYMACHINE, Version=2.0.11587.0, ProcessId=<snip/>
Listening on http://localhost:8888/
而且,至关重要的是,我在发布到 Azure 时遇到的错误也开始在本地表现出来。
好的,现在运行时都同步了,是时候开始修复我的实际错误了 :)