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

时间:2017-07-07 17:50:40

标签: azure visual-studio-2017 azure-functions

我在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)

9 个答案:

答案 0 :(得分:62)

命令行优先于设置文件,问题是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进程的命令行参数来自行查看。

编辑:一个单词

答案 1 :(得分:17)

我正在使用CLI版本1.2.1,Application arguments中的以下Project Properties -> Debug设置对我有用。

host start --port 7074 --nodeDebugPort 5860

答案 2 :(得分: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功能核心工具(根据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”类型问题时失败,所以我想确保本地执行使用相同的函数运行时天蓝色(即2.0.11587.0,根据上面的设置说明,它应该是,对吧?)

所以,根据@ ravinsp的说明,我在我的C盘上运行一个find找到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时遇到的错误也开始在本地显示。

好的,现在运行时全部同步,时间开始修复我的实际错误:)

答案 3 :(得分:5)

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

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

host start --pause-on-error --nodeDebugPort 5860

答案 4 :(得分:3)

如果您使用的是Visual Studio for MacOS,请右键单击您的项目,单击“选项”,单击Run -> Configurations -> Default,然后在“参数”字段中输入host start --port 7073 --pause-on-error

答案 5 :(得分:3)

为此

选择 Function App Project in Visual Studio -> Hit Alt+Enter 并导航至Debug设置并设置

host start --port 8085 --nodeDebugPort 6890

答案 6 :(得分:1)

更新项目属性->调试以下内容

主机启动-端口7073-错误暂停

enter image description here

答案 7 :(得分:1)

从此版本开始:

Azure Functions Core Tools (3.0.2912 Commit hash: bfcbbe48ed6fdacdf9b309261ecc8093df3b83f2)
Function Runtime Version: 3.0.14287.0

您只需要在“应用程序参数”框中键入start --port 7074

答案 8 :(得分:0)

这是我在 local.settings.json 文件中使用不同端口的方式,同时在 Intellij 中运行它。您也可以使用任何其他 IDE,local.settings.json 无处不在。

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "java"
  },
  "Host": {
    "LocalHttpPort": 7072
  },
  "ConnectionStrings": {}
}