113

I am setting local host port in local.setting.json. Referring Microsoft doc https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local

The file looks like below

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

When I run/debug the solution , VS still host the app on default port (7071)

I have checked the bin directory, the local.setting.json file is geting there with above settings. Running Azure Fucntion CLI (func host start) from bin directory correctly read the port number.

Looks like VS is not using the "LocalHttpPort" port. Is there any other changes required in the settings. I have Visual Studio 2017 Preview (2)

Janusz Nowak
  • 2,595
  • 1
  • 17
  • 36
Ramkumar Singh
  • 2,240
  • 4
  • 15
  • 18

11 Answers11

140

I am using the CLI version 1.2.1, and the following Application arguments setting in Project Properties -> Debug worked for me.

host start --port 7074 --nodeDebugPort 5860

Community
  • 1
  • 1
Thuc Nguyen
  • 1,621
  • 1
  • 11
  • 10
124

Update: If you're just looking to change the port, you don't have to set it through the file specified in the question. Check Thuc Nguyen answer

Original answer:

the command line takes precedence over the settings file, the problem is that VS passes an explicit port on the command line.

work around is to go through project -> properties -> Debug, then under Application arguments take control of the args. you can type host start --pause-on-error

enter image description here

Edit from ravinsp:

Update for .Net Core 2.0 function project:

The command line arguments you have to pass are different. You have to pass in the path to a dll in front. Like this: %AppData%\..\Local\Azure.Functions.V2.Cli\2.0.1-beta.22\Azure.Functions.Cli.dll host start --pause-on-error You can see for yourself by running the function in Visual Studio and using the process explorer to see command line args to dotnet.exe process.

edit: a word

ahmelsayed
  • 7,125
  • 3
  • 28
  • 40
  • 3
    Alas this does not work with the .NET Core 2.0 version of the Functions tooling, only the .NET Framework version. – System.Cats.Lol Jan 11 '18 at 17:30
  • 3
    In .Net Core 2.0, you have to give the following as the command line args. I found this out via process explorer while running the function via VS. Put this in the "Application Arguments" field: C:\Users\\AppData\Local\Azure.Functions.V2.Cli\2.0.1-beta.22\Azure.Functions.Cli.dll host start --port 8888 --pause-on-error – ravinsp Jan 29 '18 at 09:25
  • With VS 2017 15.9.4 for .Net Core 2.0, I added the following json {"host":{"LocalHttpPort":7073}} near the end of my local.settings.json file. Next I created in the project/Properties/Debug a new Project Profile and set its Application arguments to: start --port 7073 --pause-on-error . Note the profile is set to "Project" not Executable. This allows me to have multiple test profiles. With this setup I can run multiple Azure Functions at the same time in debug in Visual Studio when I set the Solution Properties Configuration to Multiple. – Larry Aultman Jan 03 '19 at 15:42
  • With VS 2019, and function 2.22.0, this has changed to: %LOCALAPPDATA%\AzureFunctionsTools\Releases\2.22.0\cli\func.exe" host start --port 7071 --pause-on-error – Turbo Jun 11 '19 at 01:43
49

Update Project Properties -> Debug to following

host start --port 7073 --pause-on-error

enter image description here

CuriousGuy
  • 3,818
  • 4
  • 24
  • 28
10

As of this version:

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

you only have to type start --port 7074 in the Application Arguments box

Richard
  • 627
  • 7
  • 14
7

Correct answer for .NET Core 2.0 / .NET Standard 2.0 Azure Functions project in Visual Studio 2017 when you have installed Azure Functions Core Tools 2.x Runtime via NPM

I followed @ahmelsayed's answer and in particular, @ravinsp's comments for .net core 2.0 comments. While very helpful and putting me on the right track, they did not work for me without a crucial and non-intuitive modification so I'm adding a fresh answer.

TL;DR;

If you've used NPM to install Azure Functions Core Tools 2.x Runtime then you may need to set Project/Properties/Debug/Application Arguments to:

C:\Users\<myuserid>\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\func.dll host start --port 8888 --pause-on-error

Long answer follows ...

My Setup

During this exercise, my setup is fully up to date (at time of writing) and as follows:

  • Visual Studio 2017 Professional: 15.6.2
  • Azure Functions and Web Job Tools: 15.0.40215.0
  • Windows 10 10.0.16299 Build 16299
  • Azure Functions Core Tools (installed as per the Develop and run Azure functions locally document from Microsoft) reports (in Git Bash):

    me@MYDESKTOP ~ $ func <snip/> Azure Functions Core Tools (2.0.1-beta.24) Function Runtime Version: 2.0.11587.0

fwiw, the Functions App settings tab for this Functions App on Azure reads:

Runtime version: 2.0.11587.0 (beta)

My Issue

When I run my functions project (with no application arguments) I get this in the console output:

[17/03/2018 21:06:38] Starting Host (HostId=MYMACHINE, Version=2.0.11353.0, ProcessId=<snip/>
Listening on http://localhost:7071/

This in and of itself might not be a problem, but I'm getting annoying "works on my machine, fails when publishing to azure" type issues, so I want to make sure that local execution is using same functions runtime as azure (i.e. 2.0.11587.0 which, as per the setup notes above, it is/should be, right?)

So, based on @ravinsp's instructions, I run a find on my C drive to locate Azure.Functions.Cli.dll - there's only one, and it's located at C:\Users\<myuserid>\AppData\Local\Azure.Functions.V2.Cli\2.0.1-beta\Azure.Functions.Cli.dll which seems very consistent with @ravinsp's answer.

So, I add the following 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

then I DO get port 8888, but runtime weirdly is still being reported as 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/

Solution

Given that running func from Git Bash as per the above showed runtime of 2.0.11587.0, I tried which func which returned /c/Users/<myuserid>/AppData/Roaming/npm/func . I did a cat on it and long story short I could see that ultimately it was running C:\Users\<myuserid>\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\func.exe, and that in that same directory there was a func.dll.

So, I tried the following 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

then finally I do get ...

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

and, crucially, the error I was getting when publishing to Azure starts manifesting itself locally too.

Ok, now the runtimes all in sync, time to get down to fixing my actual bug :)

ubienewbie
  • 1,771
  • 17
  • 31
7

To do this

Select the Function App Project in Visual Studio -> Hit Alt+Enter and navigate to Debug settings and set

host start --port 8085 --nodeDebugPort 6890
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
6

I used the accepted answer but I still got an error when the debugger port was trying to bind because both function apps were trying to bind to 5858.

To get around that I added one more attribute to the application arguments in the project settings and my arguments look like this:

host start --pause-on-error --nodeDebugPort 5860
Jeff LaFay
  • 12,882
  • 13
  • 71
  • 101
5

Using Visual Studio 2022 and Function v4, you could set the port in the launchSettings.json file: enter image description here

{
  "profiles": {
    "<functionapp project name>": {
      "commandName": "Project",
      "commandLineArgs": "--port 7137",
      "launchBrowser": false
    }
  }
}

This setting can also be updated through UI:
Properties > Debug > General > Open debug launch profiles UI: enter image description here

Thomas
  • 24,234
  • 6
  • 81
  • 125
4

If you're using Visual Studio for MacOS right click on your project, click Options, click on Run -> Configurations -> Default and enter host start --port 7073 --pause-on-error in the Arguments field.

kbanner
  • 149
  • 6
3

This is the way I use a different port in local.settings.json file, while running this in Intellij. You can use any other IDE as well, local.settings.json works everywhere.

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "java"
  },
  "Host": {
    "LocalHttpPort": 7072
  },
  "ConnectionStrings": {}
}
Vipin
  • 4,851
  • 3
  • 35
  • 65
0

Using the following in the "Command line arguments" in VS 2022 and .Net 6 works: start --port 7074

Ralph
  • 51
  • 4