如何在Visual Studio中的其他端口上运行Azure Function应用程序

问题描述 投票:33回答:4

我在local.setting.json中设置本地主机端口。参考Microsoft doc https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local

该文件如下所示

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "AzureWebJobsDashboard": ""   
  },
  "Host": {
    "LocalHttpPort": 7073
  }
}

当我运行/调试解决方案时,VS仍然在默认端口上托管应用程序(7071)

我已经检查了bin目录,local.setting.json文件正在进行上述设置。从bin目录运行Azure Fucntion CLI(func host start)正确读取端口号。

看起来VS没有使用"LocalHttpPort“端口。设置中是否需要进行任何其他更改。我有Visual Studio 2017 Preview(2)

azure visual-studio-2017 azure-functions
4个回答
64
投票

命令行优先于设置文件,问题是VS在命令行上传递了一个显式端口。

周围的工作是通过project -> properties -> Debug,然后在Application arguments控制args。你可以输入host start --pause-on-error

enter image description here

从ravinsp编辑:

.Net Core 2.0功能项目的更新:

您必须传递的命令行参数是不同的。你必须将路径传递到前面的dll。像这样:%AppData%\..\Local\Azure.Functions.V2.Cli\2.0.1-beta.22\Azure.Functions.Cli.dll host start --pause-on-error您可以通过在Visual Studio中运行该函数并使用进程资源管理器查看命令行参数来查看dotnet.exe进程。

编辑:一个字


17
投票

我使用的是CLI版本1.2.1,Application arguments中的以下Project Properties -> Debug设置适用于我。

host start --port 7074 --nodeDebugPort 5860


7
投票

当您通过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评论的评论。虽然非常有帮助并且让我走上了正确的轨道,但如果没有一个关键且非直观的修改,它们就无法为我工作,所以我正在添加一个新的答案。

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 Professional:15.6.2
  • Azure功能和Web作业工具:15.0.40215.0
  • Windows 10 10.0.16299 Build 16299
  • Azure Functions核心工具(根据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设置选项卡显示:

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时失败”类型问题,所以我想确保本地执行使用与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的答案非常一致。

所以,我添加以下Project / Properties / Debug / Application Arguments:

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

所以,我尝试了以下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

然后我终于得到......

[17/03/2018 21:16:29] Starting Host (HostId=MYMACHINE, Version=2.0.11587.0, ProcessId=<snip/>
Listening on http://localhost:8888/

而且,至关重要的是,我在发布到Azure时遇到的错误也开始在本地显示。

好的,现在运行时都是同步的,有时间来修复我的实际bug :)


5
投票

我使用了接受的答案,但是当调试器端口试图绑定时我仍然遇到错误,因为两个函数应用程序都试图绑定到5858。

为了解决这个问题,我在项目设置中为应用程序参数添加了一个属性,我的参数如下所示:

host start --pause-on-error --nodeDebugPort 5860
© www.soinside.com 2019 - 2024. All rights reserved.