How to run Azure Function app on a different port in Visual Studio

Viewed 60723

I am setting local host port in local.setting.json. Referring Microsoft doc https://docs.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)

11 Answers

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

Update Project Properties -> Debug to following

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

enter image description here

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

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

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

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.

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

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": {}
}

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

Related